I’m a newbie with Meteor. I need help with how to render a template as a PDF. I found a couple packages: pascoual:pdfjs & pascoual:pdfkit. I have gotten it to work so that my route automatically downloads a PDF. The route looks like this:
Router.route('/orders/dl_pdf/:_id', {
name: 'order.pdf',
action: function () {
var order = Orders.findOne({ _id: this.params._id });
var doc = new PDFDocument({size: 'A4', margin: 50});
doc.fontSize(12);
doc.text("Invoice #" + order.orderNumber, 10, 30, {align: 'center', width: 200});
this.response.writeHead(200, {
'Content-type': 'application/pdf',
'Content-Disposition': "attachment; filename=order-" + this.params._id + ".pdf"
});
this.response.end( doc.outputSync() );
}, where: 'server'
});
But I have a couple issues with this. One thing is, I would have to build the entire PDF in doc.text(); I want to learn how to pull my text from a template (if possible). And I want to show the PDF in the browser instead of downloading it.
Am I using the right packages? Any advice or even a pointer to an outside tutorial so I can figure it out. I tried doing my own searching but am having trouble finding a decent tutorial that actually helps me.