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
{{ message }}
Repository navigation
PDFKit crashes when providing fonts as Buffer in table #1743
btw seems that putting font buffer in columnStyles and rowStyles have the same issue even with the suggested fix.
The DefinitelyTyped type definitions didn't include fonts options in columnStyles or rowStyles though.
changed the title [-]PDFKit crashes when providing fonts as Buffer in table cells[/-][+]PDFKit crashes when providing fonts as Buffer in table[/+]on Jun 25, 2026
btw seems that putting font buffer in columnStyles and rowStyles have the same issue even with the suggested fix.
The DefinitelyTyped type definitions didn't include fonts options in columnStyles or rowStyles though.
So i'm leaning toward only allowing font aliases on table styles. To be fair, the font option in table is not documented at all so is just a matter of documentation
// check for existing font familes with the same name already in the PDF
// useful if the font was passed as a buffer
if(
(font=this._fontFamilies[this._font.name])&&
isEqualFont(this._font,font)
){
this._font=font;
returnthis;
}
My original use case was to make something like table builder that supports providing fonts with Uint8arrays as the font may be fetched from online sources. Registering an alias for the font would require hashing the buffer or extracting the font name from the buffer if I want the alias not to duplicate.
btw seems that putting font buffer in columnStyles and rowStyles have the same issue even with the suggested fix.
The DefinitelyTyped type definitions didn't include fonts options in columnStyles or rowStyles though.
Oh so at best it will just skip the font registeration on duplicated font buffers. At least GC seems working so the concern is the expensive font creation and comparison. The problem worsens when using column / row options as the font buffer will be applied on every affected cell
So i'm leaning toward only allowing font aliases on table styles. To be fair, the font option in table is not documented at all so is just a matter of documentation
The unsupported font error somehow makes sense now :p
Activity
ykw9263 commentedon Jun 25, 2026
A workaround is to register the font with
registerFontand use the alias in table cell font, like belowblikblum commentedon Jun 25, 2026
Please, open a PR with this change
@hollandjake any thoughts?
ykw9263 commentedon Jun 25, 2026
Thanks, I will fork and open one.
btw seems that putting font buffer in
columnStylesandrowStyleshave the same issue even with the suggested fix.The DefinitelyTyped type definitions didn't include fonts options in
columnStylesorrowStylesthough.[-]PDFKit crashes when providing fonts as Buffer in table cells[/-][+]PDFKit crashes when providing fonts as Buffer in table[/+]blikblum commentedon Jun 26, 2026
@hollandjake is this by design?
hollandjake commentedon Jun 26, 2026
@blikblum definitely sounds unintentional
blikblum commentedon Jun 27, 2026
I examined the font loading and concluded that allowing passing font buffer to font.src options in table row options is a foot gun.
Doing:
Would load 3 different font instances
So i'm leaning toward only allowing font aliases on table styles. To be fair, the font option in table is not documented at all so is just a matter of documentation
ykw9263 commentedon Jun 27, 2026
I haven't look deeper into the font loading mechanism yet. Does these lines deduplicates font buffers before loading?
pdfkit/lib/mixins/fonts.js
Lines 87 to 95 in 0036303
My original use case was to make something like table builder that supports providing fonts with Uint8arrays as the font may be fetched from online sources. Registering an alias for the font would require hashing the buffer or extracting the font name from the buffer if I want the alias not to duplicate.
ykw9263 commentedon Jun 27, 2026
By the PDFKit documentation on Tables Column options and Row options extends Cell options, which includes options for font. So I guess it was a miss
blikblum commentedon Jun 27, 2026
One line above the font instance is created. This code, AFAIK, does not save any resource
ykw9263 commentedon Jun 27, 2026
Oh so at best it will just skip the font registeration on duplicated font buffers. At least GC seems working so the concern is the expensive font creation and comparison. The problem worsens when using column / row options as the font buffer will be applied on every affected cell
The unsupported font error somehow makes sense now :p
blikblum commentedon Jun 27, 2026
Using
familyprop togetther with src: buffer will avoid the font creation every timeykw9263 commentedon Aug 21, 2026
Seems fixed in #1770. Should I close the issue then?
ykw9263 commentedon Aug 21, 2026
Oh the PR missed the
deepMerges insidenormalizedRowStyleandnormalizedColumnStyleinlib/table/style.jspdfkit/lib/table/style.js
Lines 61 to 63 in 7438d8a
pdfkit/lib/table/style.js
Lines 117 to 119 in 7438d8a
Passing font as buffers in column and row styles still fails with
Error: Not a supported font format or standard PDF fontShould be an easy fix by applying the same patch to these two functions.