Android Question PDF with dynamic page length

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I am using the Printing library to generate a sales ticket/invoice in PDF format.
The problem is that the ticket can have an indeterminate length, from a single sales line to hundreds of sales lines.
The problem is that the user wants it to be emailed in PDF format and from what I have seen in the Printing library examples it is necessary to declare the page size.
How can I solve this issue?
Thank you very much.
 

vecino

Well-Known Member
Licensed User
Longtime User
I solved it by calculating the size of the text according to the number of lines and multiplying by how much each line of text occupies.
This way I create the pdf file with a height that depends on the text it will contain.
Thank you!
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, the library is called "Printing", it is here:
Printing library
To calculate the height of the page I simply multiply the number of lines the ticket carries by the height of the font I'm using.
I add 128 if I have to present the company logo and I add another 128 if I have to present the customer's signature (I use those fixed measures, 128).
It's very simple, but it works for me.
B4X:
' Receives the number of lines in the note (including header, footer, etc.), and whether it has a logo and signature.
Sub CalcularAltoParaPDF( iLineas As Int, bLlevaLogo As Boolean, bLlevaFirma As Boolean, iAltoFontSize As Int ) As ResumableSub
    Dim iPS As Float = 254/72        '' the pdf measurements are in 1/72nd of an inch (postscript)
    Dim iAlto As Int
    '
    iAlto = iLineas * (iAltoFontSize/iPS)
    '
    If bLlevaLogo Then
        iAlto = iAlto + (128/iPS)
    End If
    If bLlevaFirma Then
        iAlto = iAlto + (128/iPS)
    End If
    iAlto = iAlto * iPS
    '
    Return iAlto
End Sub
 
Upvote 0
Top