Android Question save Pdf when Create in a directory

MroBurk

Member
Licensed User
Hi, I need help for saving a created pdf into a specific folder, and (the folder) if not exist I need to create... Thanks to any ideas


PanelToPdf:
Private Sub PanelToPdf(Panel As B4XView, FileName As String)
    Dim pdf As PdfDocument
    pdf.Initialize
    pdf.StartPage(595, 842) 'A4 size
    Dim bmp As B4XBitmap = Panel.Snapshot
    Dim dest As Rect
    dest.Initialize(10, 10, 0, 0)
    dest.Width = bmp.Width / bmp.Scale
    dest.Height = bmp.Height / bmp.Scale
    pdf.Canvas.DrawBitmap(bmp, Null, dest)
    pdf.FinishPage
    Dim out As OutputStream = File.OpenOutput(provider.SharedFolder, FileName, False)
    pdf.WriteToStream(out)
    out.Close
    pdf.Close
    
    Dim in As Intent
    in.Initialize(in.ACTION_VIEW, "")
    provider.SetFileUriAsIntentData(in, FileName)
    in.SetType("application/pdf")
    StartActivity(in)
End Sub
Panel to PDF.
thanks for any Ideas
 

Attachments

  • 1.zip
    10.7 KB · Views: 85

MroBurk

Member
Licensed User
the code allows to save the file, but if you try to open that file, it is damaged.. with *.txt it works very well but it does't work with *.pdf.. you can try yourself with the posted project... Maybe I did anything wrong...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sleep(15000)
    File.WriteString(File.DirInternal, "1.pdf", "pdf")
    Wait For (SaveFile(File.OpenInput(File.DirInternal, "1.pdf"), "application/octet-stream", "1.pdf")) Complete (Success As Boolean)
    Log("File saved successfully? " & Success)
1. You don't this sleep call.
2. The code makes no sense.

B4X:
SaveFile(File.OpenInput(provider.SharedFolder, FileName), "application/pdf", "pdf")
 
Upvote 0

MroBurk

Member
Licensed User
Thank you so much EREL...There is a Course toLearn all this? I want to learn how to develop app and improve myself... thank you again!
 
Upvote 0
Top