The error apppeared after I upgraded pdfkit from 0.7.2 to 0.8.0. Fontkit version: 1.5.4. (I'm not sure what version was there before the upgrade).
Error: Variations require a font with the fvar, gvar, and glyf tables.
at TTFFont.getVariation (/home/kola/server/node_modules/pdfkit/node_modules/fontkit/index.js:11966:13)
at TTFFont.getFont (/home/kola/server/node_modules/pdfkit/node_modules/fontkit/index.js:12000:17)
at Object.fontkit.create (/home/kola/server/node_modules/pdfkit/node_modules/fontkit/index.js:75:21)
at Object.fontkit.openSync (/home/kola/server/node_modules/pdfkit/node_modules/fontkit/index.js:43:18)
at Function.PDFFont.open (/home/kola/server/node_modules/pdfkit/js/font.js:14:24)
at PDFDocument.font (/home/kola/server/node_modules/pdfkit/js/mixins/fonts.js:39:28)
The error occurs when I use .registerFont and .font.
doc = new PDFDocument( size: 'letter', margin: 0 )
doc.registerFont('light', 'public/assets/font/OpenSans-Light.ttf', 'OpenSans-Light')
doc.font('light').fillColor('white').fontSize(18).text('Hello', 0, 8, align: 'center')
There is no error when I use the path to the font every time.
doc.font('public/assets/font/OpenSans-Light.ttf').fillColor('white').fontSize(18).text('Hello', 0, 8, align: 'center')
For TTF fonts, you don't need the postscript name (second argument), since there is only one font in the file. That argument is for TTC or DFont files which are font collections, with multiple fonts in one file.
Most helpful comment
For TTF fonts, you don't need the postscript name (second argument), since there is only one font in the file. That argument is for TTC or DFont files which are font collections, with multiple fonts in one file.