Android Question Create pdf from url

hung

Active Member
Licensed User
Longtime User
I want to create a pdf file from an url. The url contains image and barcode. The url could be sent to printer then print or save as pdf without problem.

But I want to create pdf without showing the printer screen. I tried the following but always got blank pdf. Any hints?

B4X:
    wv_pdf.LoadUrl(argurl)
    Wait For wv_pdf_PageFinished (Url As String)

    Dim lpdf As PdfDocument
    lpdf.Initialize
    lpdf.StartPage(595,842) ' a4

    Dim lbmp As Bitmap
    lbmp = wv_pdf.CaptureBitmap
    Dim lrect As Rect
    lrect.Initialize(0,0,595,842)
    lpdf.Canvas.DrawBitmap(lbmp, lrect, lrect)
    lpdf.FinishPage
 
    gRp.CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, result As Boolean)
    If result Then
        Dim outs As OutputStream = File.OpenOutput(File.DirInternal, argfilename, False)
        lpdf.WriteToStream(outs)
        outs.Close
    End If
    lpdf.Close
 

DonManfred

Expert
Licensed User
Longtime User
The url contains image and barcode
I don´t think the max url-size can hold an image. The url is limited to around 2048 bytes.
The url could be sent to printer then print or save as pdf without problem
The Printer must Support such a feature.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
B4X:
        Dim outs As OutputStream = File.OpenOutput(File.DirInternal, argfilename, False)
Why are you requesting external storage write permission and then writing your data to File.DirInternal?
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
B4X:
        Dim outs As OutputStream = File.OpenOutput(File.DirInternal, argfilename, False)
Why are you requesting external storage write permission and then writing your data to File.DirInternal?
oh. output to file.DirExternal does not work
 
Upvote 0

hung

Active Member
Licensed User
Longtime User
I want to create a pdf file from an url. The url contains image and barcode. The url could be sent to printer then print or save as pdf without problem.

But I want to create pdf without showing the printer screen. I tried the following but always got blank pdf. Any hints?

B4X:
    wv_pdf.LoadUrl(argurl)
    Wait For wv_pdf_PageFinished (Url As String)

    Dim lpdf As PdfDocument
    lpdf.Initialize
    lpdf.StartPage(595,842) ' a4

    Dim lbmp As Bitmap
    lbmp = wv_pdf.CaptureBitmap
    Dim lrect As Rect
    lrect.Initialize(0,0,595,842)
    lpdf.Canvas.DrawBitmap(lbmp, lrect, lrect)
    lpdf.FinishPage
 
    gRp.CheckAndRequest(gRp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, result As Boolean)
    If result Then
        Dim outs As OutputStream = File.OpenOutput(File.DirInternal, argfilename, False)
        lpdf.WriteToStream(outs)
        outs.Close
    End If
    lpdf.Close
I found the issue and fixed that.

The wv_pdf must be visible, even with width 1dip, before capturebitmap, or blank will be captured.
 
Upvote 0
Top