Here's the lowdown on how Chromium flips web pages into PDFs with Blink and PDFium.
The Rendering Pipeline
When you ask Chrome to "Print to PDF," a sophisticated pipeline kicks in. It starts with Blink (Chrome's rendering engine) and ends with PDFium (its PDF library).
Step 1: Layout with Blink
Blink takes your HTML/CSS and computes the layout. For print, it switches to a paginated layout mode, respecting @page rules, break-before/break-after properties, and page dimensions.
Step 2: Paint to Skia
Once layout is computed, Blink paints the content using Skia, Google's 2D graphics library. Skia renders text, images, shapes, and gradients into a canvas that can be serialized to various formats.
Step 3: PDF Generation with PDFium
The painted content is then passed to PDFium, which converts the Skia output into a proper PDF document. PDFium handles:
- Font embedding and subsetting
- Image compression
- Vector graphics preservation
- PDF metadata and structure
Step 4: Output
The final PDF is assembled with all pages, embedded fonts, and compressed images. The result is a faithful reproduction of your web page in PDF format.
Why This Matters for Doppio
Doppio leverages this exact pipeline via headless Chromium, giving you programmatic access to Chrome's print-to-PDF functionality through a simple REST API. This means you get the same quality output as Chrome's built-in PDF generation, but automated and scalable.