Render PDF Invoices from HTML Without a Browser in Your Backend

Tired of bloated serverless bundles with Chromium? SnapPDF converts your HTML invoice to PDF via a simple GET request. No browser needed. Get raw PDF bytes

miércoles, 29 de julio de 2026 • 3 min read • Q2BSTUDIO Team

Cómo Convertir Facturas HTML a PDF sin Chromium

In enterprise software development, generating PDF invoices from HTML is a recurring need. Traditionally, this involves embedding a headless browser like Chromium in the backend, which drastically increases container size, slows cold starts, and complicates deployment in serverless environments. At Q2BSTUDIO, as a company specialized in custom software, we have seen how this approach can become an unnecessary bottleneck. There is a cleaner alternative: delegate the rendering to an external service that accepts a public URL and returns the PDF bytes. That way, the browser lives on another machine and your backend only orchestrates the call and stores the result.

The idea is simple. You have an HTML template with CSS that looks perfect in the customer’s browser. The accountant asks for a PDF, but you don’t want to carry Chromium. An API like SnapPDF exposes a single GET endpoint where you pass the URL of your rendered invoice and get the PDF binary. Parameters like format, background, or wait_for_selector let you adjust the output without touching backend code. At Q2BSTUDIO we recommend this pattern because it aligns with our philosophy of lightweight and scalable architectures, whether on cloud AWS/Azure or on-premise infrastructure.

Implementation from Node.js is straightforward with native fetch. You build the URL with parameters, make the request, and read the body as an ArrayBuffer. The response is not JSON but application/pdf; an error returns JSON with an error field. It is important to validate that the content starts with %PDF-, because if the URL returns a login page, you would get HTML instead of the PDF. Also, you need to enable background=true to preserve CSS background colors, which Chromium disables by default when printing. Without that option, table headers with colored backgrounds become unreadable.

The recommended workflow is to generate a short-lived signed URL (60 seconds) when the invoice is finalized. That URL points to the HTML view you already show the customer. It is passed to the PDF service, and the received bytes are stored in an S3 bucket or Azure Blob container, indexed by invoice ID. The PDF becomes a cached artifact. Every time someone downloads it, it is served directly from storage rather than re-rendered. Your design team continues editing the HTML as usual, and the PDF regenerates automatically when needed.

From a business perspective, this approach reduces operational costs by removing the dependency on a browser in every instance. Serverless deployments are no longer limited by package size, and containers start in seconds instead of minutes. At Q2BSTUDIO we apply similar techniques when integrating AI to automate document generation processes, or when adding cybersecurity layers via signed URLs with temporary access tokens. It is also perfectly compatible with BI/Power BI solutions that need to embed dynamically generated PDFs in dashboards.

There are practical details to consider. The wait_for_selector option is best-effort: if the selector never appears, you still get a PDF of whatever loaded. It’s advisable to visually verify the result before sending it to the customer. The scale parameter is clamped by Chromium between 0.1 and 2.0; out-of-range values are silently adjusted. For pages with WebSockets or long polling, the service waits for the network to settle before printing, which lengthens the response. Invoices are static; real-time dashboards are not. That is why this pattern works especially well for transactional documents.

Another critical point: the URL you send must be publicly reachable. The service rejects loopback, private, and link-local addresses. In local development you can use a tunnel like ngrok. In production, a signed URL with a 60-second expiration provides the necessary security. At Q2BSTUDIO we often combine this with process automation using AI agents that orchestrate the entire cycle: from order confirmation to PDF delivery by email. All without the backend having to run a single browser.

In summary, generating PDF invoices from HTML without Chromium in your backend is possible, efficient, and scalable. You only need an external service, an accessible URL, and minimal integration. This architecture fits perfectly with Q2BSTUDIO’s development principles, where we prioritize modular, secure, cloud-ready solutions. The result: a lighter, faster, and more maintainable system.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.