1

I need to generate PDF documents from some data and I also need some templating functionality. I have expirience with npm package pdfkit, but this package not support templates.

It would be nice if I will be able to make HTML or XML templates.

Any recommendations? (Not deprecated)?

3 Answers 3

1

Use JS to write HTML Files, put these on a webserver that runs on localhost (or some webserver where you can upload files to). Call Google Chrome in headless mode to convert HTML to PDF:

URL=https://localhost:8000/myfile-created-from-js.html         # some HTML file
OUTFILE=myfile-created-from-js.pdf                             # PDF file
google-chrome --disable-gpu --headless $URL --print-to-pdf     # HTML 2 PDF
mv output.pdf  $OUTFILE                                        # rename PDF

I think that initially the file will always be called output.pdf, so you have to rename it.

You can start a webserver on localhost with

'python -m SimpleHTTPServer 8000 > /tmp/simple-web-server.log 2>&1 &'

0

This project is a great match for what you want to do.

https://github.com/PDFTron/web-to-pdf

Blog describing the project: https://www.pdftron.com/blog/react/react-to-pdf/

Disclaimer this is from my company, but the web-to-pdf project is GNU AFFERO GENERAL PUBLIC LICENSE and allows commercial use.

2
  • It is using puppeteer, and I do not want to convert Recat components. But thanks :) I can use puppeteer alone then.
    – Baterka
    Commented Oct 19, 2019 at 10:15
  • React was just used for the blog post. The github project has no mention/reference to React. Yes, you can use Puppeteer alone.
    – Ryan
    Commented Oct 21, 2019 at 18:10
0

https://parall.ax/products/jspdf What about this one? This is also javascript based, and provides templates.

1
  • You could improve your answer by providing some highlights. Commented Jan 2, 2023 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.