Skip to content

wkhtmltopdf Docker Image in Production and What a Year of Keeping It Costs

A wkhtmltopdf Dockerfile takes ten minutes, then the project is archived, the apt build lacks headers and footers, and untrusted HTML can reach your network. One container prints 9,600 an hour. Here is the year of cost against an API plan.

Live demo

Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.

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 plan

Putting wkhtmltopdf in a Docker image is a ten minute job, and that is the trap. The Dockerfile works, the invoice prints, and the question of who keeps it safe and correct for the next three years never gets asked. wkhtmltopdf was archived by its maintainers in January 2023, so every image you build today freezes a tool that will not receive another fix. This article covers what a production image really involves, what a month-end batch looks like, and a year of cost against an API plan, with every assumption labelled so you can swap in your own.

The short answer

Keep wkhtmltopdf in Docker only if your templates are simple tables and text, nobody outside your company controls the HTML, and the volume is a few thousand documents a month. If your HTML comes from users, uses flexbox or grid, or needs JavaScript, the engine will cost you more in workarounds than a managed renderer costs in fees. In the example below a year of self-hosting costs roughly seven times the yearly price of a 50,000 render API plan, almost all of it people time.

Why is the wkhtmltopdf Docker image harder than it looks?

Three things bite, usually in this order.

  • The apt package is not the real tool. The version in Debian and Ubuntu repositories is built against an unpatched Qt, which drops features such as headers, footers and page offsets that the project's own patched builds provide. Teams copy the "install wkhtmltopdf" line from a tutorial, then discover --footer-center does nothing. The fix is to download the patched .deb from the wkhtmltopdf downloads page that matches your base image, and to repeat that whenever you change the base.
  • Fonts are your problem. A slim image has almost no fonts, so text falls back to a default face and the PDF stops matching your brand. You add font packages, then your own web fonts, then test every language you print.
  • The engine is frozen. It renders with an old WebKit fork. Flexbox and grid layouts break, and JavaScript is unreliable, so charts arrive empty. If a template looks right in Chrome and wrong in the PDF, this is why. Our output does not match the browser article lists the seven usual causes.

Is wkhtmltopdf safe to run on untrusted HTML?

Not without isolation. In August 2022 researchers disclosed CVE-2022-35583, a server side request forgery in wkhtmltopdf 0.12.6, where HTML can make the converter fetch internal addresses and embed the response in the PDF. The project is archived, so there is no patched release to move to. If any part of the document can be influenced by a customer, such as a name field, a description or an uploaded logo URL, treat the container as a hostile workload: no access to cloud metadata addresses, no route to internal services, a read only filesystem, and a hard timeout. That is real work, covered in more depth in HTML to PDF API security.

What does one wkhtmltopdf container handle per hour?

Take a realistic job. A render takes 1.5 seconds for a four page invoice with one web font. wkhtmltopdf is one process per document, so you run 4 worker processes in a container with 2 GB of memory. These are planning assumptions, not benchmarks, so time a representative template before you size anything.

ItemValueResult
Seconds per render1.5
Workers42.7 renders a second
Per hour4 divided by 1.5, times 3,6009,600
Month-end run of 50,00050,000 divided by 9,6005.2 hours

That throughput is better than a headless Chrome pool, which is the honest case for wkhtmltopdf. What it does not show is queueing. If 30,000 invoices are requested in the first hour, the last customer waits more than three hours for a download link unless you add containers, and then you are running an autoscaling job queue as well.

What does a year of self-hosting cost?

Assumptions, all labelled: 12 hours to build the image, fonts, queue and timeouts, 24 hours across the year to rebuild images, chase font and layout bugs and apply isolation, $100 an hour fully loaded, and two small containers at $30 a month for redundancy.

Cost lineBasisYear one
Build and harden12 hours at $100$1,200
Maintenance24 hours at $100$2,400
Containers2 at $30 a month$720
Self-hosted total$4,320
SitePDF Growth, 50,000 renders a month$99 list, about $49 a month on yearly billing$588

On those figures self-hosting is about seven times the Growth plan in year one. Halve the labor and it is still about four times. The gap closes only when volume is tiny or when documents must never leave your network. The new work an API does not remove is the HTML itself: if your template relies on old WebKit quirks you will touch it once, then it renders like Chrome.

How do you replace wkhtmltopdf in a Docker service?

The migration is smaller than people expect, because the input is the same HTML. You replace the shell call with one HTTP request.

curl -X POST https://api.sitepdf.com/v1/render \
  -H "Authorization: Bearer $SITEPDF_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Invoice 8842</h1>...", "page_size": "Letter", "margin": "18mm", "archive": true}'

Set archive to true and SitePDF also keeps a dated copy of exactly what it rendered, which is useful when a customer disputes an invoice. Teams comparing vendors before they commit can also use research tools such as marketagent.ai to map who else sells in the space. For the full side by side with the old binary, read the wkhtmltopdf alternative page, and for the other self-hosting options see library versus API. Python users of the wrapper can read the pdfkit cost article.

When wkhtmltopdf in Docker is still fine

Keep it when the HTML is entirely yours, the layout is tables and text, volume is low and steady, and the PDFs never include anything a user typed. Pin the patched binary, drop all network access from the container, set a timeout, and write down the date you plan to move. Treat it as a bridge, not a platform.

Frequently asked questions

How do I install wkhtmltopdf in a Docker image?

Download the patched .deb that matches your base image from the wkhtmltopdf downloads page and install it with apt, then add font packages. The package from the distribution repository uses unpatched Qt and loses headers, footers and some page options, so it often behaves differently from the version you tested locally.

Is wkhtmltopdf deprecated?

Yes in practice. The repository was archived in January 2023, so there are no further releases, fixes or security patches. It still runs, and many services use it, but the engine is an old WebKit fork that cannot handle modern CSS reliably.

What replaces wkhtmltopdf in production?

Anything built on current Chromium. You can run headless Chrome with Puppeteer or Playwright, host a Chromium service such as Gotenberg, or call a managed rendering API with the same HTML. The first two keep the operational cost with you, the API moves it to the vendor.

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.

Get started

Render and archive with one API call

A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.

HTML to PDF, in your browser

Buy the plan