0

I am working on a billing app, with Sails.js and angular and ejs.

All is fine but now I want (NEED) to save the html invoice as a PDF. I looked on npmjs to find something that would help and so I found html-pdf. It took me hours to get it to render my browser view and CSS and pictures, but I got there. The moment it worked, I tried putting the header tag in my ejs to set up headers for multiple pages invoice, and the header lost CSS and pictures... You can see an example of my code there : My question.

Because of that question not being answered, I started searching and looking around for a fix and the only answer I got, suggested I use wkhtmltopdf. I installed the cmd-line tool (even though I don't like having to install a tool just for this) and manage to get it to work with my code but the CSS and pictures are gone. Yeah back to square one.

I tried many adaptations and it only results in error from my controller. Looking around for example, I found a post in here suggesting using PDFkit instead of wkhtmltopdf.

Once again I tried to modify my code for PDFkit, but after turning around for about one hour I give up.

I would like to know if either wkhtmltopdf or PDFkit, or another npm package is better for what I want to do.

Can someone advise me on how to detect if a package is outdated and obsolete (I picked the first one because it seemed downloaded a lot in the past days, according to npmjs website, and the answer I got told me it was old and obsolete).

StS
  • 49
  • 1
  • 11

1 Answers1

0

We have a similar approach of building up HTML and CSS with a templating engine and then converting this to PDF. I can recommend Puppeteer to render and save to PDF.

We are currently implementing this and plan to move this exercise to AWS Lambda function calls as we expect dozens of pages per PDF.

Manuel Reil
  • 508
  • 2
  • 10
  • Ok this looks good, but can you tell me if, instead of a url I can send a string of the view of my browser ? (I use this line presently : `document.getElementById('printPdfSection').innerHTML` ). The examples As of yet we don't have specific urls per invoice. I need to be able to have a header if the invoice as more than one page (With page number if possible), and it also have to respect the CSS. Can Puppeteer do all that ? Also I see that it install Chromium ? The app is running on a CentOS server, do I have anything special to do ? – StS Nov 27 '17 at 13:27