PDFFont.heightAtSize returns full height without a way to get y offset
See original GitHub issueI am using some custom handwriting styled fonts (like https://fonts.google.com/specimen/Alex+Brush) to implement my own electronic signatures. These fonts have some pretty crazy tails on some letters. pdf-lib draws text from the baseline, above these tails. PDFFont.heightAtSize returns the height above and below the baseline, which on standard fonts the extra height is negligible but these handwriting fonts can add substantial amounts.
I am styling a pdf-fillable app using css which places text from the top-left corner and I am trying to get that html view to match up with the generated pdf view. In order to do that I have to calculate the height of the font and subtract it from the x/y position I placed in html to draw correctly in pdf-lib. Using the height from heightAtSize can overshoot the signature line up to 10 pixels depending on the font.
Is there a way to obtain the font’s baseline offset or be able to draw text starting from the top left?
(The red box is the font height drawn at the same coordinates as the text. The green box uses the font size which is more accurate but still taller than the actual text from the baseline.)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)

Top Related StackOverflow Question
Thanks @hopding, I appreciated the insight. Haven’t had time to investigate further but the 3/4 workaround has been good enough to get by.
I’m going to close this issue for now. Please feel free to reopen if you’d like to discuss this further.