Private Sub ButtonEnvoyer_Click
env.CheckAndRequest(env.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
CustomListView1.sv.Height=3000dip
Dim bmp As B4XBitmap=CustomListView1.sv.Snapshot
pdf.Initialize
pdf.StartPage(595, 3500) 'A4 size
Dim Bitmap1 As Bitmap
Bitmap1.Initialize(File.DirAssets,"logoR.png")
Dim DestRect As Rect
DestRect.Initialize(10, 10, 500, 139)
pdf.Canvas.DrawBitmap(Bitmap1, Null, DestRect)
pdf.Canvas.DrawText("Text 1", 270, 190, Typeface.DEFAULT_BOLD, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "CENTER")
' Ajouter le texte de l'EditText au PDF
'Dim texte As String = ACEditText1.Text
'pdf.Canvas.DrawText(texte, 300, 220, Typeface.DEFAULT, 14 / GetDeviceLayoutValues.Scale, Colors.Black, "CENTER")
Dim texte As String = ACEditText1.Text
Dim largeur As Int = 550 ' largeur de la zone de dessin en pixels
Dim textPaint As Paint
textPaint.Initialize
textPaint.TextSize = 14 / GetDeviceLayoutValues.Scale ' taille du texte en dp
Dim layout As StaticLayout
layout.Initialize(texte, textPaint, largeur, Layout.Alignment.ALIGN_NORMAL, 1.0, 0.0, False)
Dim ligneCount As Int = layout.LineCount
Dim yPos As Int = 220
For i = 0 To ligneCount - 1
Dim lineStart As Int = layout.GetLineStart(i)
Dim lineEnd As Int = layout.GetLineEnd(i)
Dim lineText As String = texte.SubString2(lineStart, lineEnd)
pdf.Canvas.DrawText(lineText, 300, yPos, Typeface.DEFAULT, 14 / GetDeviceLayoutValues.Scale, Colors.Black, "CENTER")
yPos = yPos + layout.GetLineBottom(i) - layout.GetLineTop(i)
Next
pdf.Canvas.DrawText("Texte 2", 270, 250, Typeface.DEFAULT_BOLD, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "CENTER")
DestRect.Initialize(110, 270, 0, 0)
DestRect.Width = bmp.Width / bmp.Scale
DestRect.Height = bmp.Height / bmp.Scale
pdf.Canvas.DrawBitmap(bmp, Null, DestRect)
pdf.FinishPage
Dim OrigFormat As String=DateTime.DateFormat 'save orig date format
DateTime.DateFormat="dd MMM yyyy"
Dim MyDate As String=DateTime.Date(DateTime.Now)
'CheckBox
Dim Periode As String
Periode=""
If CheckBox1.Checked=True Then
Periode="AM"
Else If CheckBox2.Checked=True Then
Periode="PM"
End If
Dim DateSelect As String=btnDate.xLBL.Text
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "Texte 3" & DateSelect & " - " & Periode & ".pdf", False)
pdf.WriteToStream(out)
out.Close
pdf.Close
Dim FileName As String = "Texte 4" & DateSelect & " - " & Periode & ".pdf"
'copy the shared file to the shared folder
DateTime.DateFormat=OrigFormat 'return to orig date format
File.Copy(File.DirRootExternal, FileName, Starter.Provider.SharedFolder, FileName)
Dim email As Email
email.To.Add("mail@mail.com")
email.Subject = "Texte Mail"
email.Attachments.Add(Starter.Provider.GetFileUri(FileName))
Dim in As Intent = email.GetIntent
in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
StartActivity(in)
End If
End Sub