1

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?

SudiB
  • 223
  • 2
  • 13
  • I think you might need to put your fonts in the /public/fonts directory to be accessible. The public folder goes in the root directory of your meteor project if you haven't created one. http://docs.meteor.com/#/full/structuringyourapp – chackerian Feb 28 '16 at 02:02
  • @SudiB: have you found a solution? – Aki Sep 06 '22 at 18:08

1 Answers1

0

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

prat_raj21
  • 11
  • 5