How to know length of text before writing

Help
2012-08-29
2013-05-28
  • I want to align text right. To do this I need to know how long a text will be in the pdf before writing. When I know the length of the text string I can position it more left or right depending of the length. I use different types of fonts with different font styles (BOLD,REGULAR).

    How I can figure out what length a text string will occupy?

     
  • mtraut
    mtraut
    2012-08-30

    You can use PDFontTools.getGlyphWidthEncoded to compute the run length of a given string. The string must be encoded using the font encoding before.