B4J Question jPDFJet - Splitting long strings

ziovec

Member
Licensed User
Hello there!

I'm using jpdfjet to generate a pdf document from a web server.
I noticed that when I'm drawing a pdf line with a string as input, it doesn't take care of the lenght of the strings, and that result in a very awful pdf :\

This is the way I'm drawing the line:
B4X:
    pdfLine2.SetFont(HelveticaItalic14)
    pdfLine2.SetPosition(15, 15+pdfLine2.GetDestinationY+HelveticaItalic14.GetHeight)
    pdfLine2.SetText($"«${nota}»"$)
    pdfLine2.DrawOn(PDFPage)

Variable $nota is a string created from an html input text:
B4X:
        Dim f As Future = txtNota.GetVal
        nota = f.Value
It can be infinite long and can contain multiple break lines (wich would be cool to track in order to re-write the string as the user initially intended).

How can I automatically draw more lines when the string lenght is over a certain value? I should be able to tell how many lines are needed given the length of the string, I guess...any suggestion? :D
 

AHilton

Active Member
Licensed User
Longtime User
Just create yourself a Wordwrap function that splits up your string into lengths that you know your document space can handle by putting CRLF at the breaks. When you get back from that function, split up that string that was passed back with Regex.Split to give a string array. Then loop over that string array with your .SetPosition and .SetText.
 
Upvote 0
Top