Skip to content

HTML to PDF in Docker With a Chromium Container or a Rendering API and What a Year Costs

A Chromium container prints what the browser shows, but shared memory, fonts and patching add up. At 20,000 documents a month the API route costs about $888 in year one against about $4,920.

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

SitePDF is an HTML to PDF API, and this article is for a team that wants to run HTML to PDF in Docker and is deciding between its own Chromium container and a hosted renderer. The short answer is that the container starts easily and gets expensive at the edges, in memory limits, fonts and image patching, and that at 20,000 documents a month the API route costs about $888 in year one against about $4,920.

The short answer

A Chromium container prints exactly what the browser shows, which is the reason teams choose it. The trouble is that a container is a sandbox inside a sandbox. Chromium wants shared memory, system fonts and a user namespace, and Docker defaults give it less than it expects, so the first PDF works on a laptop and the tenth under load does not.

If you already run containers for everything, have an engineer who knows Chromium flags and print fewer than a few thousand documents, a container is reasonable. If PDFs are a side feature of a billing or reporting product, the API removes a service you would otherwise own.

What breaks when you run Chromium in Docker?

ProblemWhat you seeUsual fix
Small shared memory, 64 MB by defaultPages crash on long documents with a "target closed" errorRaise --shm-size or pass --disable-dev-shm-usage
Sandbox needs user namespacesChromium refuses to start as rootRun as a non root user with a seccomp profile, or disable the sandbox and accept the risk
Slim images carry no fontsInvoices print with boxes or the wrong fontInstall font packages and your brand fonts in the image
Zombie browser processesMemory climbs until the container is killedClose browsers in a finally block, restart workers on a schedule
Image size and patchingA 1 GB image and a Chromium update every few weeksA rebuild and redeploy pipeline you must keep running

The Puppeteer project keeps a current list of these in its troubleshooting guide, including the Docker section, and it is worth reading before you commit to the container route. For the layout problems that follow once it runs, see our notes on fonts that do not load and the timeouts on large pages.

What does a Docker based PDF service cost for a year?

These are planning assumptions, not measurements, so replace them with your own. A SaaS prints 20,000 invoices and statements a month. Building the container, a queue worker, retries and a font setup takes 24 hours at $100 an hour. Keeping it healthy, with Chromium updates, memory tuning and the odd incident, takes 1.5 hours a month. Two small machines for headroom cost $60 a month.

ItemBasisYear one cost
Build the container and worker24 hours at $100$2,400
Upkeep and incidents1.5 hours a month at $100$1,800
Machines$60 a month$720
Container total$4,920
Integrate the APIabout 3 hours at $100$300
SitePDF Growth, 50,000 renders a month$99 list, $588 billed yearly$588
API total$888

Only the $588 repeats in year two, while the upkeep line keeps going. Hiring one more person to carry that line is its own project, and if that is where your team is, a screening tool such as Recruitingbot is aimed at the first sift of applicants. The honest comparison is the upkeep you pay forever, not the price of the first container.

What does the container route look like?

FROM node:20-slim
RUN apt-get update && apt-get install -y chromium fonts-liberation fonts-noto \
    --no-install-recommends && rm -rf /var/lib/apt/lists/*
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
USER node
CMD ["node", "worker.js"]

# run with
docker run --shm-size=1g --security-opt seccomp=chrome.json pdf-worker

That is the easy half. The worker, the queue, retries on a crashed page and a way to wait for a chart before printing are still yours. The Puppeteer alternative page lists what a managed renderer takes over.

How do you call the API instead?

curl -X POST https://api.sitepdf.com/v1/render \
  -H "Authorization: Bearer $SITEPDF_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Invoice INV-20418</h1>...", "format": "Letter", "wait_for": "#total", "archive": true}'

Your container shrinks to the app you already run. With archive set, the render is also stored with a SHA-256 hash, which the invoice PDF archive page explains. SaaS products sending invoices on one day of the month can read the sizing on HTML to PDF API for SaaS.

Who this is for and who it is not for

It is for teams that print invoices, statements or reports from a product and would rather not own a Chromium service. It is not for teams that cannot send document content to an outside service, or that print so many documents that a tuned in house cluster is cheaper than the highest plan. The general sums are in the library against API article.

What to do this week

Look at your incident log for the last quarter and count the PDF related ones. If you have none and a person who enjoys the container, keep it. If there are several, post one real invoice to SitePDF and compare it with your current output. Plans are on the pricing page.

Frequently asked questions

How do I run Puppeteer in Docker for PDF generation?

Install Chromium and fonts in the image, run as a non root user, give the container enough shared memory with --shm-size and close each browser after use. Then add a queue so that a crash retries one document and not the whole batch.

Why does Chromium crash in Docker?

The most common cause is the 64 MB shared memory default, which long pages exceed. The second is the sandbox, which needs user namespaces that many container setups do not allow. Raising shm size or using a seccomp profile fixes most crashes.

Is it cheaper to self host HTML to PDF in Docker?

Only at very high volume or when the platform work is free. For a product printing 20,000 documents a month, build and upkeep time outweighs the hosting bill, which is why the API comes out lower in the example above.

How much does an HTML to PDF API cost?

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.

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