Android Question pdf.Canvas.DrawText

Giusy

Active Member
Licensed User
Hi,

I have a string longer than the horizontal width of an A4 sheet.
The string is truncated.
How can I make it develop over several lines?
Thank you
 

Giusy

Active Member
Licensed User
You can measure the length of the string with Canvas.MeasureStringWidth(Text As String, Typeface As Typeface, TextSize As Float).
And if the length is wider than the page width split it and write the rest onto the next line.
Yes, I used Canvas.MeasureStringWidth(Text As String, Typeface As Typeface, TextSize As Float)
but what it means to use "split"
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When the length of the text is longer than the width of the page you need to separate the text into two or more parts.
For each part, the text length must be smaller than the page width.
You can get the position of the last empty character with Index = Text.LastIndexOf(" ")
Then with Text.Substring(0, Index) you can get the first part.
Measure its length and if it's smaller than the page width write on the first line Text.Substring(0, Index)
And on the second line Text.Substring(Index + 1, Text.Length)
If the length of Text.Substring(0, Index) is still wider than the page.
Get the index of the next empty character with Index = Text.LastIndexOf2(" ", Index - 1).
And so on.
 
Upvote 0

Giusy

Active Member
Licensed User
When the length of the text is longer than the width of the page you need to separate the text into two or more parts.
For each part, the text length must be smaller than the page width.
You can get the position of the last empty character with Index = Text.LastIndexOf(" ")
Then with Text.Substring(0, Index) you can get the first part.
Measure its length and if it's smaller than the page width write on the first line Text.Substring(0, Index)
And on the second line Text.Substring(Index + 1, Text.Length)
If the length of Text.Substring(0, Index) is still wider than the page.
Get the index of the next empty character with Index = Text.LastIndexOf2(" ", Index - 1).
And so on.
@klaus thank's for your job
I was hoping there was something automatic, patience.
I get back to work
thank you again
 
Upvote 0

Giusy

Active Member
Licensed User
Where is the relevant code? What have you tried?
Hi @Erel
I am attaching a small test example. I don't know how to replace the output from label1 to pdf.
My strings do not contain CRLF.
Thanks
 

Attachments

  • EXAMPLE.zip
    9.6 KB · Views: 290
Upvote 0
Top