6

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.

6
  • The best thing I know is jsPDF, although their HTML renderer is marked with "early stages" label for over a year. Commented Mar 14, 2014 at 12:35
  • That's very close to what I need but unfortunately it only scrapes text. I need to keep my page formatting in terms of tables, borders, images etc. Commented Mar 14, 2014 at 14:13
  • @A_L you could use spiderable/phantomjs to render your pages to wkhtml2pdf to directly change your rendered html page to a pdf Commented Mar 14, 2014 at 20:47
  • I also have this need. If anyone reading this has actually built a solution to achieve this, can you please post an answer outlining what you used and how you did it? Or even post a simple project on Github? Thanks! Commented Mar 16, 2014 at 15:51
  • @Akshat I installed wkhtmltopdf on my meteor server and I am able to generate pdf's from URL using the command line but I don't knowhow to do this from within meteor - do you have any pointers? Commented Mar 17, 2014 at 13:50

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

This doesn't work for Javascript heavy sites like Meteor. wkhtmltopdf doesn't have browser like environment to load the data on the client side.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.