Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the better way to generate pdf using javascript and/or php?

I have a web app and I need print the data into pdf. In back-end I use php, while in front-end a javascript MVC framework (backbone.js).

I don't know if generate the pdf only using javascript (..then using data cache) or using ajax that will call a php page that will generate the pdf... What's the better solution?

Naturally I need be able to print, save and use the stylesheet for pdf.

Thanks.

like image 916
keepyourweb Avatar asked Nov 08 '11 15:11

keepyourweb


1 Answers

I prefer mPDF to generate PDFs:

You can generate the PDF using PHP and grab it by doing an AJAX call, that's the only good way. Of course in mPDF you can style document using CSS.

If you want read PDF using javascript, read: Open Source Javascript PDF viewer

edit: now it's 2016 and mPDF is for sure not recommended, deprecated piece of software. There exists much better ones, just take a look at GitHub:

PHP: https://github.com/search?l=PHP&o=desc&q=pdf&ref=searchresults&s=stars&type=Repositories&utf8=%E2%9C%93

JavaScript: https://github.com/search?utf8=%E2%9C%93&q=node+pdf&type=Repositories&ref=searchresults

like image 182
PiKey Avatar answered Sep 21 '22 10:09

PiKey