You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @AntoninD-Galadrim, since there is no other content on the row and the row is dynamically sized (since you haven't specified the height), it means that the height is the smallest it can be hence the alignY does nothing in this case.
If you enable table({debug: true, ...}) you will see where the bounds of your text is.
What you are likely looking at is a result of either the fonts baseline being wrong, or you have modified the text baseline.
If you are still seeing this, can you send a screenshot with debug enabled
Thank you for that, managed to replicate too. Investigating, it seems that the calculation for how high a line is, is always factoring in the lineGap despite that line being the last line in the string. This replicated the same behaviour as the heightOfString method. @blikblum thoughts on whether this is correct behaviour?
For reference this also occurs in the doc.text method, moving the last lines y position to the next line including the gap.
If we don't want this behaviour and we want the last line to exclude the gap. with some tweaks to the lineWrapper, and the heightOfString function. we can get the following:
Where the height of the first textBox is computed with heightOfString you can see the line it cut, however the doc.y position is still including the gap so subsequent calls still use the gap. Code branch: https://github.com/hollandjake/pdfkit/tree/text-last-line-gap
Assuming lineGap is the equivalent to line height is should be applied only between lines of text, description from google / AI:
Font line height, also known as "leading," is the vertical space between lines of text. It's a fundamental typographic practice, impacting readability and making text easier to scan and understand. Line height is set in CSS, either by a percentage of the font size or a fixed length unit.
Elaboration:
Measurement:
Line height is measured from the baseline of one line to the baseline of the next.
Units:
It can be expressed in various units like pixels (px), em, rem, or as a percentage of the font size.
Impact on Readability:
Proper line height ensures enough space between lines, preventing text from looking dense and crowded, especially when using smaller fonts.
if we want, we could preserve existing behaviour (including the trailing space) by putting it behind an option flag in the heightOfString / boundsOfString / table functions
if we want, we could preserve existing behaviour (including the trailing space) by putting it behind an option flag in the heightOfString / boundsOfString / table functions
It is better. You can use this option in table and let current behavior in other places
@blikblum just been doing some more testing and I noticed that the trailing line gap issue is only occuring in the system fonts, using roboto it does not cause it. could this be a disparity between system font and the internal font?#
Not sure if this is the same issue or a new one, but I added a lineGap to one of my cells with alignment of { x: 'left', y: 'center' } and it does not align. All the other cells do align as expected. My ultimate goal is to add a bit of padding above and below the text in each cell.
If I add a new dummy column with some text and the same line gap & alignment, it does not align but the previous cell mentioned in the first sentence does align, like the rest of the cells. All of these columns are set to center on the y property.
Tested on node 22.14.0 with pdfkit 0.17.2 and 0.17.4.
Activity
hollandjake commentedon Jun 9, 2025
Hi @AntoninD-Galadrim, since there is no other content on the row and the row is dynamically sized (since you haven't specified the height), it means that the height is the smallest it can be hence the alignY does nothing in this case.
If you enable
table({debug: true, ...})you will see where the bounds of your text is.What you are likely looking at is a result of either the fonts baseline being wrong, or you have modified the text baseline.
If you are still seeing this, can you send a screenshot with debug enabled
hollandjake commentedon Jun 9, 2025
For reference here is what your example code generates (with debug enabled for clarity)
AntoninD-Galadrim commentedon Jun 12, 2025
@hollandjake
This is what I get on my end, default font and everything.
hollandjake commentedon Jun 12, 2025
Thank you for that, managed to replicate too. Investigating, it seems that the calculation for how high a line is, is always factoring in the lineGap despite that line being the last line in the string. This replicated the same behaviour as the
heightOfStringmethod. @blikblum thoughts on whether this is correct behaviour?For reference this also occurs in the
doc.textmethod, moving the last lines y position to the next line including the gap.If we don't want this behaviour and we want the last line to exclude the gap. with some tweaks to the lineWrapper, and the heightOfString function. we can get the following:
Where the height of the first textBox is computed with
heightOfStringyou can see the line it cut, however the doc.y position is still including the gap so subsequent calls still use the gap. Code branch: https://github.com/hollandjake/pdfkit/tree/text-last-line-gapblikblum commentedon Jun 12, 2025
At first look no.
Need to look for the possible behavior changes in other use cases.
blikblum commentedon Jun 12, 2025
Assuming lineGap is the equivalent to line height is should be applied only between lines of text, description from google / AI:
Font line height, also known as "leading," is the vertical space between lines of text. It's a fundamental typographic practice, impacting readability and making text easier to scan and understand. Line height is set in CSS, either by a percentage of the font size or a fixed length unit.
Elaboration:
Units:
It can be expressed in various units like pixels (px), em, rem, or as a percentage of the font size.
Impact on Readability:
Proper line height ensures enough space between lines, preventing text from looking dense and crowded, especially when using smaller fonts.
blikblum commentedon Jun 12, 2025
Although the specs hints it applies only between text lines, in browser css it affects before and after text
https://developer.mozilla.org/en-US/play?id=arr45vJCgMKYeU1CksvmAB7uY9pKTMusgCGBNY5ZHI20jxBn9azXgmoDR9QaEgN9RhY3%2Brkx5EglCwRG
We should evaluate how other pdf libs, typesetting systems (typst), handle this
hollandjake commentedon Jun 16, 2025
@blikblum findings so far:
pdfmake:

css:

iterm:

quest pdf:

if you want any more let me know.
if we want, we could preserve existing behaviour (including the trailing space) by putting it behind an option flag in the heightOfString / boundsOfString / table functions
blikblum commentedon Jun 16, 2025
It is better. You can use this option in table and let current behavior in other places
hollandjake commentedon Jun 17, 2025
@blikblum just been doing some more testing and I noticed that the trailing line gap issue is only occuring in the system fonts, using roboto it does not cause it. could this be a disparity between system font and the internal font?#
helvetica (system default):
roboto (custom font):
hollandjake commentedon Jun 17, 2025
using the feature flag on a default system font, we can now achieve the following:
Use on a custom font does not seem to cause or break when using the flag
blikblum commentedon Jun 18, 2025
Good find
custom font uses fontkit, system font are handled internally
i will look at it ASAP
AntoninD-Galadrim commentedon Aug 5, 2025
Thanks for the work everyone.
Any news/fixes on this ?
AntoninD-Galadrim commentedon Sep 3, 2025
@blikblum Sorry for the ping, do you know if there is some fix or workaround ?
blikblum commentedon Sep 3, 2025
Its my next task. I looed at a list bug past weekend. Will look at it next
AntoninD-Galadrim commentedon Sep 23, 2025
Sorry to bother again, any news on this ?
blikblum commentedon Sep 27, 2025
Started analysis. Tracked the difference values when rendering a table cell. Now discover why the difference
blikblum commentedon Oct 4, 2025
My conclusions
There's nothing inherently wrong with table alignment code
The difference is how standard and embedded fonts are rendered
Standard font (Helvetica) are rendered on the top of line height while embedded (Roboto) adds a little padding to the top
Standard has lineGap positive value while embedded is 0, so it "fixes" when not including lineGap in line height calculation
Here is a program that demonstrates the difference
Result:
console output:
So, how to fix it?. At this stage, i don't know
Need to investigate if the way standard fonts are rendered is the expected
Also, test with other fonts Courier, Inter etc
mike-ayres commentedon Jan 13, 2026
Not sure if this is the same issue or a new one, but I added a
lineGapto one of my cells with alignment of{ x: 'left', y: 'center' }and it does not align. All the other cells do align as expected. My ultimate goal is to add a bit of padding above and below the text in each cell.If I add a new dummy column with some text and the same line gap & alignment, it does not align but the previous cell mentioned in the first sentence does align, like the rest of the cells. All of these columns are set to
centeron theyproperty.Tested on node 22.14.0 with pdfkit 0.17.2 and 0.17.4.