Android Question pdf.Canvas.DrawText

Discussion in 'Android Questions' started by Giusy, Mar 15, 2019.

  1. Giusy

    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
     
  2. klaus

    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.
     
  3. Giusy

    Giusy Active Member Licensed User

    Yes, I used Canvas.MeasureStringWidth(Text As String, Typeface As Typeface, TextSize As Float)
    but what it means to use "split"
     
  4. klaus

    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 likes this.
  5. Giusy

    Giusy Active Member Licensed User

    @klaus thank's for your job
    I was hoping there was something automatic, patience.
    I get back to work
    thank you again
     
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. Giusy

    Giusy Active Member Licensed User

    Hi @Erel
    I read my strings like this
    Code:
    For HH=0 To QTR
            
    Dim pnl As B4XView = clv1.GetPanel(HH)
            
    Dim lbl As B4XView = pnl.GetView(0)
            CIC=lbl.text
    But Pdf does not recognize "drawview"
    I don't know how to do it, can you give me a small example?
    It's very important for me.
    Thanks a lot
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. Giusy

    Giusy Active Member Licensed User

  10. Erel

    Erel Administrator Staff Member Licensed User

    Where is the relevant code? What have you tried?
     
  11. Giusy

    Giusy Active Member Licensed User

    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
     

    Attached Files:

  12. Erel

    Erel Administrator Staff Member Licensed User

  13. Giusy

    Giusy Active Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice