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
 

klaus

Expert
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.
 

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"
 

klaus

Expert
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.
 

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
 
Top