Android Question xCustomListView to mail

MetalOS

Member
Licensed User
Longtime User
Hello everyone,

I am looking for an example to email the contents of an xCustomListView. I would like to convert it to pdf format before sending it by email. Sorry I'm a beginner and really don't know how to do it.

Thank you in advance for your help.
 

MetalOS

Member
Licensed User
Longtime User
So I tried converting the image from XcustomListView to PDF and also adding text but I encountered errors while performing the convertion. here is my code.

B4X:
Private Sub ButtonEnvoyer_Click
    CustomListView1.sv.Height=3000dip
    Dim bmp As B4XBitmap=CustomListView1.sv.Snapshot
  
  
Dim DestRect As Rect
    pdf.Initialize
    pdf.StartPage(595, 842) 'A4 size
    pdf.Canvas.DrawLine(2, 2, 593 , 840, Colors.Blue, 4)
    pdf.Canvas.DrawText("Hello", 100, 100, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.Yellow, "CENTER")
    pdf.Canvas.DrawBitmap(bmp, Null, DestRect)
    pdf.FinishPage
    Dim out As OutputStream = File.OpenOutput(File.DirInternal, "Ronde.pdf", False)
    pdf.WriteToStream(out)
    out.Close
    pdf.Close
End Sub

ERROR: java.lang.RuntimeException: Object should first be initialized (Rect).
 
Last edited:
Upvote 0

MetalOS

Member
Licensed User
Longtime User
Here is a modification of my code which makes the errors disappear but no pdf file is created on the internal storage. Anyone have an idea?

B4X:
Private Sub ButtonEnvoyer_Click
    rp.CheckAndRequest(rp.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, 842) 'A4 size
        pdf.Canvas.DrawLine(2, 2, 593 , 840, Colors.Blue, 4)
        pdf.Canvas.DrawText("Hello", 100, 100, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.Yellow, "CENTER")
        DestRect.Initialize(30, 30, 0, 0)
        DestRect.Width = bmp.Width / bmp.Scale
        DestRect.Height = bmp.Height / bmp.Scale
        pdf.Canvas.DrawBitmap(bmp, Null, DestRect)
        pdf.FinishPage
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, "Ronde.pdf", False)
        pdf.WriteToStream(out)
        out.Close
        pdf.Close
    End If   
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
but no pdf file is created on the internal storage.
I am not familiar with pdf library, what I can tell you is.:
File.DirInternal should be: rp.GetSafeDirDefaultExternal("") or File.DirRootExternal
since you are requesting permission. You do not need permission if you store in File.DirInternal
 
Upvote 0

MetalOS

Member
Licensed User
Longtime User
it gives me this error

java.io.FileNotFoundException: /storage/emulated/0/Ronde.pdf: open failed: EACCES (Permission denied)
 
Upvote 0

MetalOS

Member
Licensed User
Longtime User
I even tried both but it doesn't change anything the pdf file doesn't create it.

B4X:
Private Sub ButtonEnvoyer_Click
    rp.CheckAndRequest(rp.GetSafeDirDefaultExternal("Download/"))
    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, 842) 'A4 size
        pdf.Canvas.DrawLine(2, 2, 593 , 840, Colors.Blue, 4)
        pdf.Canvas.DrawText("Hello", 100, 100, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.Yellow, "CENTER")
        DestRect.Initialize(30, 30, 0, 0)
        DestRect.Width = bmp.Width / bmp.Scale
        DestRect.Height = bmp.Height / bmp.Scale
        pdf.Canvas.DrawBitmap(bmp, Null, DestRect)   
        pdf.FinishPage
        Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "Ronde.pdf", True)
        pdf.WriteToStream(out)
        out.Close
        pdf.Close
    End If   
End Sub
 
Upvote 0

MetalOS

Member
Licensed User
Longtime User
With the addition of the function in the manifest file its works. Here is the final command. Thanks for your help.

B4X:
Private Sub ButtonEnvoyer_Click
    rp.CheckAndRequest(rp.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, 842) 'A4 size
        pdf.Canvas.DrawLine(2, 2, 593 , 840, Colors.Blue, 4)
        pdf.Canvas.DrawText("Hello", 100, 100, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.Yellow, "CENTER")
        DestRect.Initialize(30, 30, 0, 0)
        DestRect.Width = bmp.Width / bmp.Scale
        DestRect.Height = bmp.Height / bmp.Scale
        pdf.Canvas.DrawBitmap(bmp, Null, DestRect)   
        pdf.FinishPage
        Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "Ronde.pdf", True)
        pdf.WriteToStream(out)
        out.Close
        pdf.Close
    End If   
End Sub
 
Upvote 0

MetalOS

Member
Licensed User
Longtime User
You can also use: clv1.sv.Snapshot. You will capture more of the clv if the clv is not a mile long.
B4X:
clv1.sv.Height=3000dip
Dim bmp As B4XBitmap=clv1.sv.Snapshot


I am unable to do multiple pages on the PDF to capture all of the content of the CustomListView. It only makes me 1 page when I have 80 lines in the CustomListView.
 
Upvote 0
Top