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 |
Description
When a font is registered on the
PDFDocumentinstance usingregisterFont(alias, path), the alias works correctly withpdfDocument.font(alias)for normal text rendering. However, inside atable()cell object, specifying the font viafont: { 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:
2. This works (normal text rendering):
3. This works (table cell with
src):4. This does NOT work (table cell with registered
familyalias):Expected behaviour:
font: { family: "FAR" }inside a table cell should resolve the registered font alias and render the glyph correctly, consistent with howpdfDocument.font("FAR")works.Actual behaviour: The glyph does not render. The registered alias is not resolved when specified via
font.familyin a table cell object.Environment