How to know length of text before writing

  • Michael Ribeiro

    Michael Ribeiro - 2012-08-29

    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.


Log in to post a comment.