Building a Zero-Dependency Web Print Engine for Invoices
Leveraging CSS Paged Media, -webkit-print-color-adjust, and layout stripping to produce production-grade vector PDF invoices directly from browser print dialogs.
Why Avoid Client-Side PDF Generation Libraries?
Client-side PDF libraries (such as jsPDF or pdfmake) introduce 1.5MB to 3MB of JavaScript overhead, struggle with custom web fonts, and require complex coordinate calculations to match modern responsive layouts. Serverless Puppeteer workers add recurring cloud costs and latency.
Harnessing CSS @media print
Modern browser print engines already render web pages as native vector PDFs. By defining strict page margins and forcing color fidelity, we can transform standard HTML form views into clean, printable invoices.
@media print {
@page {
margin: 0;
size: A4;
}
html, body {
background-color: #ffffff !important;
color: #000000 !important;
cursor: auto !important;
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
}
/* Strip UI chrome, cursors, and animation overlays */
.print\:hidden,
.grain,
#cursor,
nav,
.skeletal-grid {
display: none !important;
}
/* Flatten interactive inputs into clean vector text */
input, textarea {
background: transparent !important;
color: #000000 !important;
border: none !important;
outline: none !important;
}
}Key Engineering Considerations
Inputs that allow dynamic line items must be styled so that when printed, borders and focus rings vanish, leaving pure typography aligned to an underlying grid.
Native browser print output is pure vector PDF: sharp text, zero font distortion, and 0 KB runtime bundle footprint.