server side fonts directory in pdfmake in meteor app

筅森魡賤 提交于 2019-12-24 15:45:59

问题


I am trying to create and save a pdf on the server. I have used meteorhacks:npm packaged and installed pdfmake on the server side.

My code is in a subdirectory under server directory. I am using just the example to make sure I can generate a basic pdf.

 var fonts = {
                Roboto: {
                    normal: 'fonts/Roboto-Regular.ttf',
                    bold: 'fonts/Roboto-Medium.ttf',
                    italics: 'fonts/Roboto-Italic.ttf',
                    bolditalics: 'fonts/Roboto-Italic.ttf'
                }
            };
            var PdfPrinter = Meteor.npmRequire('pdfmake/src/printer');
            var printer = new PdfPrinter( fonts );

            var dd = {
                content: [
                    'First paragraph',
                    'Another paragraph'
                ]
            };
            var pdfDoc = printer.createPdfKitDocument(dd);
            pdfDoc.pipe(fs.createWriteStream('basics.pdf')).on('finish',function(){
                //success
            });
            pdfDoc.end();

I am getting

 Error: ENOENT, no such file or directory 'fonts/Roboto-Regular.ttf'

I am a bit baffled as to where my fonts directory should be.

I tried to debug the pdfmake library and got lost. Placed the fonts directory in various places with no luck.

Any ideas?


回答1:


download roboto font and create fonts folder in the root directory and paste these dependent files.



来源:https://stackoverflow.com/questions/35677412/server-side-fonts-directory-in-pdfmake-in-meteor-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!