A_L
A_L

Reputation: 1146

Meteor template to pdf

Is it possible to convert one of my meteor templates to a pdf file? ie. build a template and then within meteor code point to it and save as a file/data maintaining the formatting and style etc.

I have had a look at pdfkit but as far as I can tell this requires manually building the pdf in code.

Upvotes: 6

Views: 1870

Answers (2)

EnergyMud
EnergyMud

Reputation: 31

Try something like this:

if(Meteor.is_server) {
  var exec;
  var file = "myPdf.pdf";
  var cmd = "wkhtmltopdf2 -q /tmp/" + file + ".html /tmp/" + file + ".pdf";

  Meteor.startup(function() {
    exec = __meteor_bootstrap__.require('child_process').exec;
  });

  exec(cmd, function(error, stdout, stderr) {
    console.log(stdout ? stdout : stderr);
  }); 
}

Upvotes: 0

manu
manu

Reputation: 1101

Try phantomjs. Follow their rasterize example to generate the pdf. You should load this library only on the server side as it's a big one.

Upvotes: 1

Related Questions