Android Question Write and Open PDF

Kiran Raotole

Active Member
Licensed User
I want to open PDF file,
Its shows message :: Can't open file trying saving the file on device and then opening it.
I written this code :

B4X:
    Dim pdf As PdfDocument
    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.FinishPage
    File.Copy(File.DirAssets,"1.pdf",File.DirDefaultExternal,"1.pdf")
    Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal, "1.pdf", True)
    pdf.WriteToStream(out)
    Dim intent As Intent
    intent.Initialize(intent.ACTION_VIEW,"1.pdf")
    intent.SetType("application/pdf")
    intent.WrapAsIntentChooser("Choose PDF Viewer")
    StartActivity(intent)

    out.Close
    pdf.Close

Whats problem?
 
Top