The journal · 30 November 2026 · 6 min read
HTML to PDF in Python With WeasyPrint or a Rendering API and What a Year Costs
WeasyPrint is free, but it runs no JavaScript, so a web view with charts needs a second template. At 8,000 invoices a month the API route costs about $588 in year one against about $4,240.
Live demo
Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.
Your HTML
Live preview
Your PDF is downloading. That was the free one. The Starter plan converts as many as you need, for $49 a month or $288 a year, half price.
See the planSitePDF is an HTML to PDF API, and this article is for a Python team choosing how to turn HTML into PDF for invoices and statements: WeasyPrint on your own server, or a Chromium based API, and what each costs over a year. The short answer is that WeasyPrint is a good, free tool for static documents, and it becomes the expensive option when your web view uses JavaScript, because you then keep two templates in step.
The short answer
WeasyPrint turns HTML and CSS into PDF without a browser. It has strong support for CSS paged media, which is why many Django and Flask teams pick it first. It does not run JavaScript and it depends on system libraries such as Pango, so the work lands on your Dockerfile and on your templates rather than on the license bill.
If your invoice is plain server rendered HTML with a table and a logo, keep WeasyPrint. If the same layout also carries a chart, a client side formatted total or a web font that behaves differently under Pango, an API that prints in real Chromium removes the second template.
Where does WeasyPrint stop being the cheap option?
| Situation | WeasyPrint | Chromium API |
|---|---|---|
| Server rendered invoice, table and logo | Works well, no license cost | Works, not needed |
| Chart drawn by a script | Not drawn, because no JavaScript runs | Drawn, wait for a selector first |
| Layout identical to the web view | Close, with a separate print stylesheet to maintain | Same engine as the browser |
| Docker image | Pango and font packages to install and patch | Nothing to install |
| Page numbers and running headers | CSS paged media, strong | header and footer fields on the call |
| Offline or air gapped use | Yes | No |
The project documents what it supports and what it leaves out in the WeasyPrint documentation, and the missing JavaScript is stated plainly there. The WeasyPrint alternative page compares the three routes side by side, and our article on why charts come out as empty boxes in WeasyPrint covers the workarounds.
What does the second template really cost?
Most of the cost is not the server. A team that already has an invoice view in the web app, with a total formatted in the browser and a small chart of usage, builds a second HTML file that WeasyPrint can print. From then on every change to a label, a column or a legal line is made twice, and the two drift apart until a customer notices a different total on the PDF than on screen.
These are planning assumptions, not measurements, so replace them with your numbers. A Python SaaS sends 8,000 invoices and statements a month. Building and testing the WeasyPrint template and its Docker setup takes 16 hours at $100 an hour. Keeping it in step with the web view, plus font and library updates, takes 2 hours a month. A small worker costs $20 a month.
| Item | Basis | Year one cost |
|---|---|---|
| Build the print template and image | 16 hours at $100 | $1,600 |
| Keep it in step, update libraries | 2 hours a month at $100 | $2,400 |
| Worker machine | $20 a month | $240 |
| WeasyPrint total | $4,240 | |
| Integrate the API | about 3 hours at $100 | $300 |
| SitePDF Starter API, 10,000 renders a month | $49 list, $288 billed yearly | $288 |
| API total | $588 |
Only the $288 repeats in year two. If your invoice never needed the second template, the static row in the first table applies and WeasyPrint stays cheaper, since its license is free. The honest comparison is one template against two, not a library against a price list.
How do you print the web view from Python with an API?
Point the render at the page the customer already sees, or send the HTML your template produced. No second layout exists, so there is nothing to keep in step.
import os, requests
resp = requests.post(
"https://api.sitepdf.com/v1/render",
headers={"Authorization": "Bearer " + os.environ["SITEPDF_KEY"]},
json={
"html": invoice_html,
"format": "Letter",
"wait_for": "#usage-chart",
"archive": True,
},
timeout=60,
)
print(resp.json())
The wait_for field holds the render until the chart element exists, and archive stores a dated copy with a SHA-256 hash, as described on the invoice PDF archive page. Statements of several pages take a "Page 2 of 7" footer through header and footer fields. A team that reconciles those statements against bank feeds afterwards might look at Reconciler for the matching step.
Who this is for and who it is not for
It is for Python teams whose invoices or statements share a layout with a web view that uses scripts, charts or web fonts, and who are tired of maintaining a print version. It is not for a team printing static HTML offline, or one that cannot send document content to an outside service. WeasyPrint or the self hosted route in the Python PDF generation guide fits those better.
What to do this week
Open your last three invoice changes and count how many touched both templates. If the answer is most of them, post one real invoice to SitePDF and compare it with the screen. Plans are on the pricing page, and the library against API article runs the general sums. If you run containers instead, see the Docker Chromium cost comparison. If you use pdfkit instead, read Python pdfkit and wkhtmltopdf against an API.
Frequently asked questions
What is the best alternative to WeasyPrint?
It depends on the document. For static invoices WeasyPrint is hard to beat on price. For pages that need JavaScript, a Chromium based renderer such as a headless browser or an HTML to PDF API is the usual alternative, because it prints what the browser shows.
Does WeasyPrint run JavaScript?
No. WeasyPrint is not built on a browser engine, so scripts never run and anything drawn after page load, such as a Chart.js chart, is missing from the PDF.
Is WeasyPrint free for commercial use?
WeasyPrint is open source under the BSD license, so there is no license fee. The cost is the engineering time to run it, keep its system libraries current and maintain a print specific template.
How much does an HTML to PDF API cost for a Python app?
SitePDF Starter API is $49 a month for 10,000 renders, or $288 billed yearly. Growth is $99 a month for 50,000 renders and Scale is $299 a month for 250,000. Count one render per document.
Written by the team behind SitePDF, an HTML to PDF API that archives every page it renders. The in-browser converter is free to try, and API plans start at $49 a month, half price billed yearly.