wkhtmltopdf migration

wkhtmltopdf as a service: POST the HTML, get the PDF

Your program needs PDFs. You do not want to start a PDF program for every page. So you run a small service: your program POSTs an HTML page, the service answers with the PDF. One address, always ready.

Marqius

Two illustrated invoice proofs aligned with a brass rule on a green desk

Many teams run such a service today on images that were last built between 2018 and 2021. This page shows the same service on the current program, in full, with working files.

Every example here was tested on 24 November 2026. Every output below is the real output, byte counts included.

What you need before you start

One of these two:

  • Docker, or
  • the program marqius-wkhtmltopdf installed on the machine.

And one file to send. We make that file first.

The sample file

Save this as invoice.html. It is a small invoice with two pages. The second page starts on a new page. The table shows borders. We will use it for every example.

html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
  body { font-family: "DejaVu Sans", sans-serif; font-size: 11px; margin: 0; }
  h1 { font-size: 18px; margin: 0 0 12px; }
  table { border-collapse: collapse; width: 100%; }
  th, td { border: 1px solid #999; padding: 6px 8px; text-align: left; }
  th { background: #f0f0f0; }
  .total { text-align: right; font-weight: bold; margin-top: 10px; }
  .page2 { page-break-before: always; }
</style>
</head>
<body>
  <h1>Invoice 1042</h1>
  <p>Acme GmbH · Nonnenstraße 11 · 20359 Hamburg</p>
  <table>
    <tr><th>Item</th><th>Qty</th><th>Price</th></tr>
    <tr><td>Widget</td><td>4</td><td>1,250.00 EUR</td></tr>
    <tr><td>Gadget</td><td>2</td><td>380.00 EUR</td></tr>
  </table>
  <p class="total">Total: 1,630.00 EUR</p>
  <div class="page2">
    <h1>Terms</h1>
    <p>Pay in 30 days. Delivery in five working days.</p>
  </div>
</body>
</html>

Start the service

With Docker, one command:

bash
docker run --rm -p 8080:80 marqius/wkhtmltopdf serve

Without Docker, if the program is installed:

bash
marqius-wkhtmltopdf serve 8080

The service prints one line when it is ready. Then ask it what it can do:

bash
curl http://localhost:8080/

It answers with its own short manual, including the exact curl lines below.

One difference between the two starts, worth knowing now: on a plain machine the service listens on 127.0.0.1 only — your machine, nobody else. Inside the Docker image it listens on every address, which is why the port mapping works. Set MARQIUS_HOST=0.0.0.0 if you want that on a plain machine too.

Four ways to send a job

All four turn the sample invoice into a two-page PDF. Way 3 also attaches the XML. Pick the one that fits your code.

Way 1: the HTML as the body, the options in the address

Use this when a plain HTTP call is enough.

bash
curl --data-binary @invoice.html \
     -H 'Content-Type: text/html' \
     'http://localhost:8080/?page-size=A4&footer-center=Page+%5Bpage%5D+of+%5Btopage%5D&footer-font-size=8' \
     -o invoice.pdf

The options after ? are wkhtmltopdf's own options. %5B and %5D are [ and ]; the address needs them written that way.

The answer: HTTP 200, 13,402 bytes, 2 pages. The bottom of each page reads:

Code
Page 1 of 2
Page 2 of 2

Way 2: a form upload, the options as JSON

Use this when you already send forms, or when the options grow long.

bash
curl -F file=@invoice.html \
     -F 'options={"page-size":"A4","footer-center":"Page [page] of [topage]","footer-font-size":8}' \
     http://localhost:8080/ \
     -o invoice.pdf

The answer: HTTP 200, 13,402 bytes, 2 pages, both footers. The same PDF as Way 1.

Way 3: with the e-invoice XML inside

Use this for invoices that must carry the machine-readable XML inside the PDF.

Save this as einvoice.xml, a small example:

xml
<?xml version="1.0" encoding="UTF-8"?>
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
                          xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100">
  <rsm:ExchangedDocument><ram:ID>1042</ram:ID></rsm:ExchangedDocument>
</rsm:CrossIndustryInvoice>

Send both files:

bash
curl -F file=@invoice.html \
     -F einvoice=@einvoice.xml \
     http://localhost:8080/ \
     -o invoice.pdf

The answer: HTTP 200, 2 pages, and the PDF carries one XML attachment named factur-x.xml. A PDF reader shows it under Attachments.

Way 4: one JSON body

Use this from code that already speaks JSON. The HTML and the options travel in one body, the HTML base64-encoded.

json
{
  "contents": "<base64 of the HTML>",
  "options": { "page-size": "A4",
               "footer-center": "Page [page] of [topage]",
               "footer-font-size": 8 }
}
bash
curl -H 'Content-Type: application/json' \
     --data-binary @payload.json \
     http://localhost:8080/ \
     -o invoice.pdf

Tested with the base64 of invoice.html: HTTP 200, 13,402 bytes, 2 pages, both footers.

From your code

Two short programs, no extra libraries. Both were run against the service and both printed the same result as the curl lines above: 13,402 bytes, 2 pages, both footers.

Python, using only the standard library:

python
import urllib.request

html = open("invoice.html", "rb").read()
req = urllib.request.Request(
    "http://localhost:8080/?page-size=A4&footer-center=Page+%5Bpage%5D+of+%5Btopage%5D&footer-font-size=8",
    data=html,
    headers={"Content-Type": "text/html"},
)
pdf = urllib.request.urlopen(req).read()
open("invoice.pdf", "wb").write(pdf)

Node, using the fetch that comes with Node 18 and later:

js
import { readFile, writeFile } from "node:fs/promises";

const html = await readFile("invoice.html");
const res = await fetch(
  "http://localhost:8080/?page-size=A4&footer-center=Page+%5Bpage%5D+of+%5Btopage%5D&footer-font-size=8",
  { method: "POST", body: html, headers: { "Content-Type": "text/html" } },
);
const pdf = Buffer.from(await res.arrayBuffer());
await writeFile("invoice.pdf", pdf);

Run it next to your app

A whole Docker Compose file:

yaml
services:
  pdf:
    image: marqius/wkhtmltopdf:latest
    command: serve
    ports:
      - "8080:80"
    restart: unless-stopped

From outside, the service is at http://localhost:8080/. Inside the same Compose network, your app calls http://pdf:80/. Tested from the host: HTTP 200, 2 pages, both footers.

The port note that saves an hour: inside the image, plain serve listens on port 80. That is why the mapping above is 8080:80. If you prefer 8080 inside too, say so — command: serve 8080, mapping 8080:8080. Both were tested.

The image is small: 13.4 MB to download for latest, 10.4 MB for slim, 17.1 MB for alpine, plus Debian-based trixie and bookworm tags.

Replacing an old wkhtmltopdf service

The service images people still pull today, checked on 24 November 2026:

Image

Pulls

Last built

insightsoftware/wkhtmltopdf

257,308

May 2020

icalialabs/wkhtmltopdf

196,616

October 2018

pukkasoftware/wkhtmltopdf

74,052

May 2018

superadm/wkhtmltopdf

70,278

May 2024

oberonamsterdam/wkhtmltopdf

50,261

March 2021

Those are lifetime counts. Most of the pulls are automation that has run for years. The people behind them are who this page is for.

All of these services share one shape: send HTML, receive a PDF. So the switch is three lines of Compose: the image, the port, the address your app calls. Your HTML does not change.

Before you cut over, check it on your own pages

  1. Keep your old service running. Save one PDF it makes: old.pdf.
  2. Start this service next to it. Send the same HTML. Save new.pdf.
  3. Compare them:
bash
marqius-wkhtmltopdf compare old.pdf new.pdf

The command gives a verdict and lists each difference with its page and its kind: text, number, date, page break, font, spacing. When the verdict reads clean, move the address and stop the old container.

Small things worth knowing

  • GET / prints the service's own manual, with the exact curl lines.
  • An address the service does not know answers 404.
  • The port comes from the command (serve 9090) or from $PORT.
  • On a plain machine the service binds to 127.0.0.1. MARQIUS_HOST=0.0.0.0 opens it to every address. The Docker image does this for you.

Questions

Does it need a browser or Java?

No. It is one statically linked program inside a 13 MB download.

Which options can I pass?

The options are wkhtmltopdf's options, written as JSON or in the address: page size, margins, headers and footers, page numbers, tables of contents.

Can wicked_pdf or python-pdfkit talk to it?

Those libraries start the program directly, and that stays the simplest path for them. The service is for programs that prefer HTTP.

Is my HTML sent anywhere?

No. The service runs on your machine or in your container. Nothing leaves it.

What does it cost?

There are two licences. The Community licence is free: for personal projects, for teaching and learning, and for open-source projects, including their CI test runs and documentation builds. The commercial licence is for businesses. Plans and licences

Who makes it?

Marqius is commercial software from Simple AI LLC. It is independent of the wkhtmltopdf project.

Sources