Sitemap

Member-only story

Effortless PDF creation from HTML using modern CSS and Puppeteer

Novel CSS features for laying out content in PDFs. Running Puppeteer as a web service in Google Cloud

10 min readMay 9, 2025

Many web applications display contents, e.g. reports, agendas, invoices that should be downloadable as PDF files.

There are a few approaches to lay out contents in a PDF. Every approach has its advantages and limitations. While contents of a simple invoice can be laid out in a PDF directly in the browser, a more robust solution is needed to generate a PDF of a multi page report illustrated with charts.

The easiest and most flexible way to lay out contents in a PDF is by using HTML and the CSS specific for printed pages.

Users can save web pages as PDFs by choosing Save as PDF in the print popup. But browsers do not offer the API for automating this operation. Programmatically it is only possible to open the print dialog by calling window.print(). Then the user would need to click Save, choose a destination folder and click Save again. That is not a good alternative for downloads upon clicking a link.

To convert styled HTML to a PDF programmatically it is necessary to use Puppeteer, a library controlling an invisible Chrome browser. Although Puppeteer does not run in…

--

--

Marian C.
Marian C.

Written by Marian C.

Java, JavaScript and SQL developer. Interested in data collection and visualization.

Responses (15)