Skip to content

HTML to PDF in C++ With an Embedded Browser or a Rendering API and What a Year Costs

C++ has no HTML engine, so every route embeds a browser or calls an API. At 20,000 documents a month the API route costs about $888 in year one against about $8,080 for an embedded engine.

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 answers the question a C++ team asks before adding PDF output to a service or desktop product: embed a browser engine and own its upgrades, or call a rendering API, and what each costs over a year. The short answer is that an embedded engine is right for an offline desktop tool, and an API is cheaper and safer for a backend that emails or archives documents.

The short answer

C++ has no built-in HTML layout engine, so every route to a good PDF from HTML goes through a browser engine. If the program runs on a user machine without a network, embed one with Qt WebEngine or CEF. If the program is a server component producing invoices, statements or reports, a rendering API removes the browser from your build, your patch schedule and your container image.

What are the options for HTML to PDF in C++?

RouteEngineWorks offlineWhat you operate
Qt WebEngine printToPdfChromiumYesA Qt build with WebEngine, its licence terms and Chromium updates
CEF (Chromium Embedded Framework)ChromiumYesLarge binaries, a message loop, sandbox setup and version bumps
wkhtmltopdf libraryOld WebKitYesAn archived project with no modern CSS, see the wkhtmltopdf alternative page
Drawing libraries such as libharu or PoDoFoNoneYesYou lay out every box yourself, there is no HTML input
Rendering API over HTTPManaged ChromiumNoAn API key and one request

Qt documents the call in the QWebEnginePage reference, and the Chromium Embedded Framework is maintained in its public repository. Both give you real Chromium output, which is the good part. The cost is that you now ship and patch a browser.

Why is a browser inside a C++ service a maintenance job?

Chromium releases security fixes often, and an embedded copy only gets them when you rebuild against a newer version. A server that renders customer supplied HTML also needs sandboxing, timeouts and a way to recover when a page hangs. None of this is hard once, and all of it recurs.

The second cost is fonts. A Linux container with no fonts installed produces PDFs with fallback glyphs, and the bug shows up only on the production image. The fonts article lists the usual causes. A third is memory: a render of a long statement can use hundreds of megabytes, so concurrency needs a pool with limits, covered in the timeout article.

What does each route cost in year one at 20,000 documents a month?

These are planning assumptions, not measurements, so replace them with your numbers. A C++ billing service sends 20,000 invoices and statements a month. Embedding CEF means 40 hours to integrate, sandbox and package, then 3 hours a month on Chromium bumps and incidents, at $100 an hour, plus a $40 a month worker container.

ItemBasisYear one cost
Integrate and package the engine40 hours at $100$4,000
Chromium bumps and incidents3 hours a month at $100$3,600
Worker container$40 a month$480
Embedded engine total$8,080
Integrate the API with libcurlabout 3 hours at $100$300
SitePDF Growth, 50,000 renders a month$99 list, $588 billed yearly$588
API total$888

At 20,000 documents a month you are above the 10,000 renders of Starter API ($49 a month, $288 billed yearly), so Growth is the plan that fits. Only the $588 repeats in year two. A team that already ships CEF for its UI has a lower integration line, and the gap shrinks.

How do you call a rendering API from C++?

With libcurl it is one POST. Build the HTML with your own template code and send it. The response carries a link to the PDF.

CURL *curl = curl_easy_init();
struct curl_slist *h = nullptr;
h = curl_slist_append(h, ("Authorization: Bearer " + std::string(getenv("SITEPDF_KEY"))).c_str());
h = curl_slist_append(h, "Content-Type: application/json");
std::string body = R"({"html": ")" + escaped_invoice_html + R"(", "format": "Letter", "archive": true})";
curl_easy_setopt(curl, CURLOPT_URL, "https://api.sitepdf.com/v1/render");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, h);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
curl_easy_perform(curl);

The render runs in managed Chromium, so flexbox, web fonts and CSS page breaks behave as in a desktop browser. With archive set to true each render is also stored with a capture time and a SHA-256 hash, described on the invoice PDF archive page. Retention is 90 days on Starter API, 365 on Growth and three years on Scale. Keep the key in the server environment, never in a shipped binary.

The same sums for Pascal are in the Delphi HTML to PDF article.

Who this is for and who it is not for

It is for C++ teams whose backend or service sends invoices, statements or reports built from HTML and wants one consistent layout without owning a browser. It is not for an offline desktop or embedded product where documents must be produced without a network, nor for teams that must keep data inside their own network.

What to do this week

Count how many PDFs you produce a month and how many hours your team spent on the engine last quarter. If the product is offline, stay with Qt WebEngine or CEF. If it is a service, post one real invoice to SitePDF and compare the output with your current one. The pricing page shows the plan for your volume, and HTML to PDF API for SaaS covers billing day bursts.

Frequently asked questions

How do I convert HTML to PDF in C++?

C++ has no HTML engine of its own. Embed Chromium through Qt WebEngine or CEF and call its print to PDF function, or send the HTML to a rendering API with libcurl and receive the PDF. The first works offline, the second removes the browser from your build.

Can Qt WebEngine print HTML to PDF?

Yes. QWebEnginePage::printToPdf renders the loaded page to a file or a buffer using Chromium. You need a Qt build that includes WebEngine and must check its licence terms for your product.

Is wkhtmltopdf still a good choice in C++?

It is archived and based on an old WebKit, so modern CSS such as grid and many flexbox layouts fail. It still works for plain documents, but new projects usually pick a Chromium based route.

How much does an HTML to PDF API cost for a C++ backend?

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