HACKER Q&A
📣 michidk

How to generate PDFs from the back end?


Ask HN: How to generate PDFs (certificates/invoices) from the backend? Can you recommend a easy to integrate service?


  👤 qw Accepted Answer ✓
I recently found out that a Norwegian government agency open sourced a micro service for generating PDF

I haven't used it, but it looks promising. You create templates based on html (Handlebars templates), which should make it easy to get started.

https://github.com/navikt/pdfgen

It may be worth a look


👤 jeilers
We are using z3c.rml (https://github.com/zopefoundation/z3c.rml) based on ReportLab. Layout is written in HTML-like XML and render performance is pretty good.

👤 bguebert
We use PDFlib, but we started using it a long time ago when there wasn't a lot of good open source options for building pdfs. PDFlib isn't open source or free. So far PDFlib has worked well and not been so expensive that we've needed to look for anything else.

https://www.pdflib.com/


👤 Leoko
Generating PDFs is a pain with most libraries, especially if the content is dynamic and should span multiple pages.

If you can use NodeJS on your backend, you might want to take a look at my PDF Library: https://github.com/DevLeoko/painless-pdf


👤 brudgers
On the command line, pdftk.

If you are using Linux, it is probably a package in your distro.

https://linux.die.net/man/1/pdftk

The homepage for the free (server) version.

https://www.pdflabs.com/tools/pdftk-server/


👤 bombcar
What do you want to do? I've done some crude ones by having a program dump values into a LaTeX template that I then ran through pdflatex.

👤 mkranjec
ReactPDF (https://react-pdf.org/) if: a) React is an option b) you (can) use nodejs on backend c) PDF preview is required on frontend (optional) d) you need to generate same PDFs on backend (optional)

👤 archydeb
Workflow I've used previously:

1. Render html (easy with a templating language e.g. Jinja for Python)

2. Turn the html into a pdf (e.g. wkhtmltopdf in Python)


👤 alhirzel

👤 ehutch79
You need to at least tell us what your backend is.

Have you googled your question yet? Is there an issue with the solutions you did find? Why would you want an external service? You could be exposing private info using external services.


👤 quickthrower2
Generate from what format and in what language?

You could run pandoc in a lambda perhaps?


👤 moritzwarhier
What backend exactly? If you're into old school PHP, try FPDF maybe. But you'll probabl have to write your own layout code.

👤 BOOSTERHIDROGEN
I'm curious maybe anyone have experience in large bank or broker how do they generate statements for customers ?

👤 NanoWar
I can absolutely recommend "gotenberg" in a docker and some react web app to render the actual web app!

👤 deadly_syn
Markdown template + pandoc would be a very minimal typeset solution.

👤 Gnarl
Clarification question: what is your backend tech?

👤 mcwhy
there is borbpdf.com