问题
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