Virtual file system Error: Helvetica.afm not found
See original GitHub issueI’ve used this webpack example to extend my create-react-app setup. I’ve added the rules to my webpack.config.js but there must a problem with the asset inlining.
in fact this rule seems not to affect my generated webpack chunk:
{ loader: 'raw-loader', test: /\.afm$/ }
the following object is applied to the webpack output, which indicates that this a problem on the loader side and not a problem with the custom registerAFMFonts
, which handles which fonts should be inlined:
var map = {
"./Helvetica.afm": "./node_modules/pdfkit/js/data/Helvetica.afm"
};
But when i double check the chunk contents there are no inlined glyphs. That’s a pity because i really appreciated the approach with kicking out all the unnecessary embedded fonts for file size reasons. In fact everything up the stack trace works well until the PDFDocument constructor tries to load the standard Helvetica font file, then the app crashes with an uncaught error…
File 'data/Helvetica.afm' not found in virtual file system
The only thing i modified is the pattern which chooses the font variants. I only want the standard Helvetica to be inlined, like this:
registerAFMFonts(require.context('pdfkit/js/data', false, /Helvetica\.afm$/));
Here’s the trace:
Uncaught (in promise) Error: File 'data/Helvetica.afm' not found in virtual file system
at VirtualFileSystem.readFileSync (virtual-fs.js:22)
at Object.Helvetica (pdfkit.es5.js:2658)
at new StandardFont (pdfkit.es5.js:2700)
at Function.open (pdfkit.es5.js:3096)
at PDFDocument.font (pdfkit.es5.js:3170)
at PDFDocument.initFonts (pdfkit.es5.js:3132)
at new PDFDocument (pdfkit.es5.js:4890)
at new PDFBuilder (PDFBuilder.js:42)
at PDFCreator.createID (index.jsx:40)
at PDFCreator.componentDidMount (index.jsx:72)
Any ideas how to ensure that the file will be inlined into the chunk or safely referenced in the virtual file system? Tbh a solution to bypass the standard font loading would be also a good hint, because my tool explicitly loads a custom font. The Helvetica i’m trying to inline is just a workaround to keep things running without breaking the whole pdfkit font-setup logic.
Cheers and thx in advance
My environment
- pdfkit version: 0.9.1
- Node version: 11.12.0
- Browser version : Chrome 74
- Operating System: MacOS 10.14.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
This issue can be closed, it was an issue with accidentally calling the require context function on the Helvetica font after force importing the raw file.
i tried various combinations, the webpack config and the browserified version. At the end i ended up taking the standalone version and copy pasting it in the project, and babel on top of it. With my current webpack config was the only thing that worked.