Android Question Multiple lines in a PDF created document

Greetings All

I am having a problem creating a simple pdf doc. All I am trying to do is create a document with many lines. I thought a new line would be generated each time I performed pdf.Canvas.DrawText but not so

If I just print one line inside the loop (x=1 to1) it is fine
I tried appending a crlf but that didn't work
I tried the s.Initialize inside and outside the loop but no effect
I have done a search but all examples seem to just show a single line output
what am I missing here?

Thanks for any suggestions

B4X:
Dim pdf As PdfDocument
    pdf.Initialize
    pdf.StartPage(595, 842) 'A4 size
    Dim x As Int
    Dim s As StringBuilder
   
    For x = 1 To 10
        s.Initialize
        s.Append(x).Append(" ").Append(P1Map1.Get("Hola" & x)).Append(" ").Append(P1Map2.Get("Hola" & x)).Append(" ")
        s.Append(P2Map1.Get("Hola" & x)).Append(" ").Append(P2Map2.Get("Hola" & x)).Append(" ").Append(CRLF)
        pdf.Canvas.DrawText(s,100,100,Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.Blue, "LEFT")
    Next
   
    pdf.FinishPage
    Dim out As OutputStream = File.OpenOutput(File.DirInternal, "1.pdf", False)
    pdf.WriteToStream(out)
    out.Close
    pdf.Close
 

emexes

Expert
Licensed User
Thanks for any suggestions
B4X:
Dim pdf As PdfDocument
    pdf.Initialize
    pdf.StartPage(595, 842) 'A4 size
    Dim x As Int
    Dim s As StringBuilder

This is mildly off-topic, but a useful tip from:

https://stackoverflow.com/questions...smallest-possible-valid-pdf/70748286#70748286

re: PDF page size is:

Whilst not defined by the rules of the question I have included some past experience of user problems.

The first difference you might note is media box in 2nd obj is a hybrid MediaBox[0 0 595 792] which is a minimax A4 width and minimax US Letter high, since otherwise the "universal page" in most countries would force a second sheet @ 100% scale printing either for too wide or too high a page definition for the locale defaults.
 
Upvote 0
Top