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
It seems FontKit has support for variation of fonts that support it via Font::getVariation({ ...features }) -> Font, but PDFKit does not expose this feature.
I've grepped through the source and could not find a way to do this already, I apologise if it's already possible some way and I'm missing something important. Please let me know.
Feature description
I imagine the ideal place is PDFFont::font taking variations as a parameter; or for future-proofing, an options object, which would currently only have variations.
fwiw I attempted this myself by adding the new option to lib/mixins/fonts.js and passed it to PDFFontFactory.open in lib/font_factory.js. Directly doing font = font.getVariation(options) in PDFFontFactory.open breaks everything with the error: First argument to DataView constructor must be an ArrayBuffer (at fontFile.end(this.subset.encode());, but goes further into FontKit).
Then I tried simply storing it in font._variations and accessed it in EmbeddedFont constructor and called getVariation there, and the error disappeared, but I could not get the variation to be applied in the output. If I moved it to the embed() method, I run into the same error as above.
I'm new to PDFKit, so if someone has ideas but not the time to add this feature, it would be nice if you could suggest where I should attempt further changes; I'd love to try.
Activity
MKRhere commentedon Jul 6, 2025
fwiw I attempted this myself by adding the new option to
lib/mixins/fonts.jsand passed it toPDFFontFactory.openinlib/font_factory.js. Directly doingfont = font.getVariation(options)inPDFFontFactory.openbreaks everything with the error:First argument to DataView constructor must be an ArrayBuffer(atfontFile.end(this.subset.encode());, but goes further into FontKit).Then I tried simply storing it in
font._variationsand accessed it inEmbeddedFontconstructor and calledgetVariationthere, and the error disappeared, but I could not get the variation to be applied in the output. If I moved it to theembed()method, I run into the same error as above.I'm new to PDFKit, so if someone has ideas but not the time to add this feature, it would be nice if you could suggest where I should attempt further changes; I'd love to try.