Bug Report
Description of the problem
When providing font in table cells with a src of Buffer or UintArray, Not a supported font format or standard PDF font. will be thrown.
Upon some digging, I found that in normalizeCell() the font object is deep-merged with other fonts in table styles
|
const font = deepMerge({}, colStyle.font, rowStyle.font, cell.font); |
This line took an unusually long time to execute, and after this the font src became something like
console.log(font.src)
// { '1': number, '2': number, '3': number, ... }
Code sample
import PDFDocument from "pdfkit";
import fs from "fs";
const doc = new PDFDocument();
doc.table().row([
{
text: 'Hello World',
font: { src: fs.readFileSync(SOME_CUSTOM_FONT), family: FONT_FAMILY },
}
])
Possible fix
Replace the font deep merge with manual property assignment.
Considering the structure of the font object a shallow merge may also be enough.
// changing to this worked properly in my case
const font = {...colStyle.font, ...rowStyle.font, ...cell.font}
Your environment
- pdfkit version: 0.19.1
- Node version: 24.15.0
- Browser version (if applicable): N/A
- Operating System: Windows 11
Bug Report
Description of the problem
When providing font in table cells with a src of
BufferorUintArray,Not a supported font format or standard PDF font.will be thrown.Upon some digging, I found that in
normalizeCell()the font object is deep-merged with other fonts in table stylespdfkit/lib/table/normalize.js
Line 96 in 2fdafa2
This line took an unusually long time to execute, and after this the font src became something like
Code sample
Possible fix
Replace the font deep merge with manual property assignment.
Considering the structure of the font object a shallow merge may also be enough.
Your environment