Skip to content

Support for font variations #1632

Open
Open

Description

@MKRhere

Feature Request

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.

doc.font("InterVariable.ttf", { variations: { wght: 900 } });

Activity

  1. MKRhere commented on Jul 6, 2025

    @MKRhere
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions