Create PDF with PDFKit Node.js package in your Meteor application, server-side only.
This package is based on PDFKit 0.4.3 and use Fiber, for best performances and non-blocking thread (but synchronous).
For the new pdfkit version (up to 0.7.1), server-side and client-side, please use the other package: pascoual:PDFKitx
meteor add pascoual:pdfkit
var doc = new PDFDocument({size: 'A4', margin: 50});
var imageBase64 = Meteor.users.findOne(this.userId).profile.picture;
var imageBuffer2 = new Buffer(imageBase64.replace('data:image/png;base64,','') || '', 'base64');
doc.image(imageBuffer2, 10, 10, {height: 75});
doc.fontSize(12);
doc.text('PDFKit is simple', 10, 30, {align: 'center', width: 200});
// Save it on myApp/public/pdf folder (or any place) with the Fibered sync methode:
doc.writeSync(process.env.PWD + '/public/pdf/PDFKitExample.pdf');
Router.route('/getPDF', function() {
var doc = new PDFDocument({size: 'A4', margin: 50});
doc.fontSize(12);
doc.text('PDFKit is simple', 10, 30, {align: 'center', width: 200});
this.response.writeHead(200, {
'Content-type': 'application/pdf',
'Content-Disposition': "attachment; filename=test.pdf"
});
this.response.end( doc.outputSync() );
}, {where: 'server'});
You can find information about the PDFKit node package here:
This package adds two Fibered methods (non-blocking thread, but synchronous):
Contributors are very welcome. There are many things you can help with, including adding testing feature, creating examples for the examples folder... Some guidelines below:
Questions: It's okay to ask a question on Github Issues if you're having trouble since the volume is manageable. Just prefix your Github Issue with 'Question: ' so we can differentiate easily. Also, please make sure you've read through PDFKit documentation and tried a few things before asking. This way you can be very specific in your question. Also, please provide a cloneable Github repository if the issue is complex. For more complex questions sometimes it's hard to get all of the context required to solve a problem by just looking at text.
New Features & Bugs: You need to ask new features and bugs corrections to PDFKit creator on his GIT: https://github.com/devongovett/pdfkit/
Answer Questions!: If you can help another user please do!
MIT