Every way to make a PDF,
and when to pick it.

Written to be useful rather than flattering. Several of these are free, and for a lot of documents they are the right answer. Each page says plainly when that is the case.

Choosing an approach

What is the best way to generate PDFs from HTML?

There are only three real approaches. Render in a browser, which is accurate but means running Chrome. Use a library with its own CSS engine, which is light but will disagree with your design. Or draw the document in code, which is exact and inflexible. Everything on this page is one of those three.

Should I use a PDF API or run my own renderer?

Volume decides it. Below a few thousand documents a month, running a browser costs more in attention than an API costs in money. Above that, your own renderer gets cheap, and the operational work is amortised over enough documents to be worth it.

Why do PDF libraries render my CSS incorrectly?

Because most of them are not browsers. Dompdf implements CSS 2.1, wkhtmltopdf froze before flexbox, WeasyPrint has its own engine with its own gaps. Only a browser-based renderer gives you what you saw on screen.

Is a free library good enough?

Very often, yes, and we say so on each page. If your document is a simple template without scripts, WeasyPrint in Python or mPDF in PHP will do the job for nothing.

What makes html4pdf different from other PDF APIs?

Nothing is stored. The document is rendered in memory and released with the response, so there is no bucket of your customers' invoices anywhere. Pricing is per document with no subscription, and credits do not expire.