Hello.
I'm working on a solution for getting the pdf generated to be saved on the server.
I have pdmake working on client side with angularjs. On the backend I hava nodejs and express.
My intention is to send an email with the pdf attached to it.
Any ideas for having this working?
Thanks... and really good work with pdfmake!
Hello,
Take a look at the examples folder - there are samples for NodeJS. I'd suggest reading the most trivial example to see the difference between client and server side.
Basically you'll need a directory with fonts (examples/fonts contains Roboto, but you can use other fonts as well)
// create a font-declaration object pointing to font files
// by default pdfmake uses Roboto, if you need more fonts, add them here
var fonts = {
Roboto: {
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italics: 'fonts/Roboto-Italic.ttf',
bolditalics: 'fonts/Roboto-Italic.ttf'
}
};
// then you create a PdfPrinter object
var PdfPrinter = require('pdfmake');
var printer = new PdfPrinter(fonts);
// and you pass the doc-definition-object to createPdfKitDocument method
var docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};
var pdfDoc = printer.createPdfKitDocument(docDefinition);
// pdfDoc is a stream so you can pipe it to the file system
var fs = require('fs');
pdfDoc.pipe(fs.createWriteStream('pdfs/basics.pdf'));
pdfDoc.end();
I hope this solves your problem.
Hi,
also thanks for this great piece of code!!!
I need to save the generated PDF on the client (phonegap app) using the FileSystem API.
Something like here:
http://docs.phonegap.com/en/2.5.0/cordova_file_file.md.html#FileWriter (Full Example FileWriter)
What is the method to get the 'raw' data after pdfMake.createPdf(docDefinition)?
Thanks in advance.
Maybe you can try to get the ArrayBuffer produced by the following:
pdfMake.createPdf(dd).getBuffer(callback function);
callback function(cb){
Save(cb.toArrayBuffer());
}
worked on some tests that i performed :)
@kstef solution is exactly what I do in the library
@juppwerner did you figure out how to save the pdf through phonegap's FileWriter?
Hi,
Is it possible to get the pdf file result encoded in a base64 string? How would that work?
Thanks!
Gonna answer this myself. I used a npm module called base64-stream and here is the code :
var base64 = require('base64-stream');
var base64stream = pdfDoc.pipe(base64.encode());
pdfDoc.end();
var tempFileBase64 = ''
base64stream.on('data',function(buffer){
var part = buffer.toString();
tempFileBase64 += part;
console.log('process data ' + part);
});
base64streamEvaluations.on('end',function(){
console.log('final output ' + tempFileBase64);
});
Thank you myself! ;)
Thanks for letting us know!
Joachim Werner
Am 9. Juni 2016 08:53:03 MESZ, schrieb flaurian [email protected]:
Gonna answer this myself. I used a npm module called base64-stream and
here is the code :var base64 = require('base64-stream'); var base64stream = pdfDoc.pipe(base64.encode()); pdfDoc.end(); var tempFileBase64 = '' base64stream.on('data',function(buffer){ var part = buffer.toString(); tempFileBase64 += part; console.log('process data ' + part); }); base64streamEvaluations.on('end',function(){ console.log('final output ' + tempFileBase64); });Thank you myself! ;)
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/bpampuch/pdfmake/issues/19#issuecomment-224814473
i can't use pdfMake.createPdfv0.1.24 in NODEJS so i used createPdfKitDocument, and i don't know how to get the arrayBuffer ... anyone here can help please
Most helpful comment
Hello,
Take a look at the examples folder - there are samples for NodeJS. I'd suggest reading the most trivial example to see the difference between client and server side.
Basically you'll need a directory with fonts (examples/fonts contains Roboto, but you can use other fonts as well)
I hope this solves your problem.