Skip to content

(font.family) Not Resolved for Registered Fonts in Table Cells #1737

@imRahulAgarwal

Description

@imRahulAgarwal

Description

When a font is registered on the PDFDocument instance using registerFont(alias, path), the alias works correctly with pdfDocument.font(alias) for normal text rendering. However, inside a table() cell object, specifying the font via font: { family: alias } does not render the font correctly — the registered alias is not resolved.

The workaround is to pass the raw file path via font: { src: path } instead, which does work. This inconsistency means registered font aliases are effectively unusable inside table cells.


Steps to Reproduce

1. Register the font:

pdfDocument.registerFont("FAR", "/path/to/fa-regular-400.ttf");

2. This works (normal text rendering):

pdfDocument.font("FAR").fontSize(18).text("\uf118", { align: "center" });

3. This works (table cell with src):

pdfDocument.table({
  defaultStyle: { border: 1 },
  data: [
    [
      "test",
      {
        text: "\uf118",
        font: { src: "/path/to/fa-regular-400.ttf", size: 20 },
      },
    ],
  ],
});

4. This does NOT work (table cell with registered family alias):

pdfDocument.table({
  defaultStyle: { border: 1 },
  data: [
    [
      "test",
      {
        text: "\uf118",
        font: { family: "FAR", size: 20 },
      },
    ],
  ],
});

Expected behaviour: font: { family: "FAR" } inside a table cell should resolve the registered font alias and render the glyph correctly, consistent with how pdfDocument.font("FAR") works.

Actual behaviour: The glyph does not render. The registered alias is not resolved when specified via font.family in a table cell object.


Environment

Property Value
PDFKit Version 0.19.0
Node.js Version 24.14.0
OS Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions