Pdfmake: Server-side rendering

Created on 28 Aug 2015  路  13Comments  路  Source: bpampuch/pdfmake

Would it be possible to have this export as a standard module so that we could also have server side PDF rendering in the cases where that is needed?

Most helpful comment

I am not familiar with meteor app but in NodeJS when I placed the fonts folder in root, it works

`

    fonts = {
        Roboto: {
            normal: './fonts/Roboto-Regular.ttf',
            bold: './fonts/Roboto-Medium.ttf',
            italics: './fonts/Roboto-Italic.ttf',
            bolditalics: './fonts/Roboto-Italic.ttf'
        }
    };

var PdfPrinter = require('pdfmake/src/printer');
    var printer = new PdfPrinter(fonts);

`

All 13 comments

I am also trying to find options for server side PDF download option, is there any examples for server side PDF generation?

I have done it following way,
pdfmake is installed in node-modules folders with following command

npm install pdfmake

The code to generate the doc as :

var PdfPrinter = require('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 have a problem to get this working because of fonts object. pdfmake installed with npm.
I followed examples/basic but I don't know how to refer to fonts or how to bipass it using common fonts. I get this error:
Error: ENOENT, no such file or directory 'fonts/Roboto-Regular.ttf'

Check the path for .ttf file, it should be from root of the node js app.

I am having the same font path problem in a meteor app on the server side. Using the simple example given above. The javascript file is under server directory. Can't find the font files. I have placed a fonts directory under my app root (same level as server and node_modules), I have placed a font directory under server, under node_modules...!! No luck. Any help is much appreciated!!

I am not familiar with meteor app but in NodeJS when I placed the fonts folder in root, it works

`

    fonts = {
        Roboto: {
            normal: './fonts/Roboto-Regular.ttf',
            bold: './fonts/Roboto-Medium.ttf',
            italics: './fonts/Roboto-Italic.ttf',
            bolditalics: './fonts/Roboto-Italic.ttf'
        }
    };

var PdfPrinter = require('pdfmake/src/printer');
    var printer = new PdfPrinter(fonts);

`

I have created small example for Server side async pdf generation in meteor
https://github.com/daupawar/MeteorAsyncPdfmake

@stemfinity It works!Thanks a lot!

pdfmake has a wonderful server example using express and node under
pdfmake/dev-playground/server.js

Hi, fellow developers. Thanks for all the great inputs shared above.

I'm trying to implement this code:

var PdfPrinter = require('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();

But there is no src/print directories inside my pdfmake directory

What I'm trying to achieve is simply saving the generated PDF into my filesystem. Any help would be much appreciated.

@daupawar was putting fonts in private (rather than public) the key for getting at fonts server-side? I'm using html-pdf in a meteor to make a PDF server-side but can't get it to work... so may switch to this package if you got custom fonts working with meteor.

In my case rebuilding docker container after adding fonts directory to root folder solved the issue

@daupawar it works!! thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MathLavallee picture MathLavallee  路  3Comments

sayjeyhi picture sayjeyhi  路  3Comments

qgliu picture qgliu  路  3Comments

davidyeiser picture davidyeiser  路  3Comments

jkd003 picture jkd003  路  3Comments