pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Server-side rendering

Open Kuzmin opened this issue 11 years ago • 13 comments

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?

Kuzmin avatar Aug 28 '15 06:08 Kuzmin

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

rajesh0188 avatar Aug 31 '15 13:08 rajesh0188

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();

psuhas avatar Sep 04 '15 21:09 psuhas

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'

sangecz avatar Sep 30 '15 14:09 sangecz

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

psuhas avatar Sep 30 '15 14:09 psuhas

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!!

ghost avatar Feb 28 '16 01:02 ghost

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);

`

ghost avatar Feb 28 '16 06:02 ghost

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

daupawar avatar Jun 28 '16 05:06 daupawar

@stemfinity It works!Thanks a lot!

mzvast avatar Jul 13 '16 09:07 mzvast

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

emotilla avatar Jan 11 '17 21:01 emotilla

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.

Gugulethu-Nyoni avatar May 08 '17 13:05 Gugulethu-Nyoni

@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.

acomito avatar Nov 30 '17 12:11 acomito

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

kasztof avatar Oct 05 '18 12:10 kasztof

@daupawar it works!! thanks.

tiveor avatar Nov 12 '20 13:11 tiveor