Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating pdf in Angular 2

Me again with another Angular 2 question.

We are trying to generate a PDF file from a html source. I searched and searched trying to find an Angular 2 wrapper for the jsPdf or makePdf libraries, but I can't find any. Is there something I am missing? Is there a pure javascript way and is that good practice? Hope you guys can help.

Thanks in advance.

Francois

like image 528
UberSwyser Avatar asked Oct 18 '22 02:10

UberSwyser


2 Answers

I was searching for the same thing, some weeks ago. I decided to do the generating on server-side (Node.js in my case). However you can do it on client-side, with jsPDF, like you mentioned.

Don't need a wrapper, just include the script and then access jsPDF through the window object. Wrapper will make it easier to test though.

I don't remember exactly but I thought it was something like this:

var doc = new window.jsPDF();
like image 172
stijn.aerts Avatar answered Oct 27 '22 11:10

stijn.aerts


PDF is a complex file format, there may be some pdf parsers/generators built with js, but they will be limited & slow, your best bet is to do something server side.

like image 20
Mark Redman Avatar answered Oct 27 '22 10:10

Mark Redman