Printing from a web app goes wrong when the browser's print engine repaginates your screen layout without print-specific CSS. The fix is a dedicated @media print stylesheet, tested at real paper sizes, plus server-side PDF generation when output must be identical on every device. Both paths have predictable failure modes you can catch before a customer prints.
Key Takeaways
- Browsers do not print what you see. They rebuild the page using print CSS, and without those rules the layout reflows unpredictably.
- A
@media printstylesheet is the highest-leverage first step: hide navigation, set@pagesize, and use real paper units like millimetres or inches. - Server-side PDF generation — headless Chrome, WeasyPrint or similar — is the right call when the paper version is a contractual deliverable.
- Test on the actual paper size your users load into the tray. A4 in Nepal, Letter in the US, and the two are not interchangeable.
- Page breaks are the most common surprise. Tables, headings and repeated footers need explicit break rules.
- Print support added after launch is harder than print support planned into the first design.
- The client owns the code and the print output. Our team can help plan, build and verify it without lock-in.
What actually happens when someone prints from a web app
Browsers do not print the DOM you see on screen. They rebuild the page using print-specific CSS, then hand a paginated document to the operating system's print driver. Most surprises come from that rebuild step.
Your screen layout optimises for a viewport. Print optimises for a paper box. The @media print rules apply only when the media type is print, and the @page rule sets paper dimensions and margins. Without it, the browser guesses from the driver's default paper. Fixed positioning, viewport units and flex containers that work on screen often misbehave on paper. This is the core mechanism to understand before you touch a stylesheet — see MDN's @media print documentation for the full picture.
Why print surprises matter in production
A misprinted invoice, receipt or waybill reads as an IT failure even when the application logic is correct. Customers blame the vendor, support tickets stack up, and staff fall back to screenshots, which look worse.
We have seen this in practice. A logistics company prints waybills with barcodes. If the barcode is clipped or low-contrast, the courier scans it manually or returns. A pharmacy label with the wrong dosage layout is a safety issue, not a cosmetic one. Print is often the last mile of a transaction. When it fails, the whole workflow stalls and the operator on the ground pays the price. The cost is trust and operator time, not just aesthetics.
When you actually need to fix print — and when you do not
Fix print output when the paper version is a deliverable: invoices, receipts, waybills, labels, contracts, tickets and reports. Skip heavy print work for dashboards, admin screens and internal tools people read on a monitor.
Ask three questions before spending time on this. Who prints? How often? What breaks if it is wrong? A customer-facing invoice needs pixel-accurate output. An internal ops dashboard may never be printed at all. If users print only occasionally, a basic print stylesheet that hides navigation and sets paper size covers most cases. Do not over-engineer a reporting pipeline for a screen the team never sends to paper.
How the browser's print pipeline works
The browser evaluates @media print rules, applies @page dimensions and margins, then flows content into discrete pages using break rules. The printer driver receives a static, paginated document, not your live DOM with its screen styles.
The @page rule sets the page box. break-before, break-after and break-inside control where pages start and where elements may split. widows and orphans control stranded lines at page edges. print-color-adjust controls whether the browser prints background colours. Each engine — Chromium, WebKit, Gecko — has quirks, but the core CSS has been stable for years. Check MDN's break rules if a specific behaviour surprises you.
Setting up reliable print support, step by step
Start with a separate print stylesheet loaded after your screen CSS so it wins the cascade. Then define paper size, hide navigation, control breaks, and test on the exact paper your users load into the tray.
- Load a dedicated stylesheet with
media="print"after the main stylesheet so its rules override screen styles. - Set
@pagesize and margins in millimetres or inches, not pixels. Pixels do not map to paper. - Hide non-print elements — navigation, buttons, filters and sidebars — with
display: noneinside the print stylesheet. - Apply break rules:
break-inside: avoidon table rows and cards,break-after: pagebefore major sections. - Force background colours and borders that matter with
print-color-adjust: exactso barcodes and brand colours survive. - Test in the browser's print preview, then export a PDF, then print one physical page at A4 and Letter.
A minimal, correct starting stylesheet looks like this:
@media print {
@page { size: A4; margin: 15mm; }
nav, .no-print, button, .filter-bar { display: none; }
table, tr, .card { break-inside: avoid; }
h2, h3 { break-after: avoid; }
* { print-color-adjust: exact; }
} Configuration that matters
Two settings cause most paper-based breakage: the @page size you declare and the paper size the printer driver expects. When they disagree, the browser scales or clips the content. Declare the size your region actually uses — A4 in Nepal, Letter in the US.
Also check driver-added headers and footers, which the browser may insert with a URL and date unless you disable them in the print dialog. A monochrome printer can turn a light grey barcode into a smudge. If the output is a label, test at the exact label dimensions, not at a full page. These details sound small. They are the difference between a clean handover and a support ticket.
How to verify print output before a customer complains
Open the browser's print preview with the correct paper size selected, export to PDF, and print one physical page. Do not trust the screen preview: pagination and margins only appear in the print preview and the exported PDF.
Use the browser's developer tools to emulate print media and inspect the applied styles. Then generate a PDF and check the page count, break positions and clipped edges. Finally, run one physical page on the printer your users actually have. Ink contrast, barcode readability and label alignment only show up on real paper. This is the step most teams skip, and it is the cheapest to do.
Failure modes and how to debug them
The common failures are blank pages, tables split across sheets, missing brand colours, and content clipped at the paper edge. Each has a specific cause in the print stylesheet or page setup, and each is reproducible in print preview.
- Blank trailing page: an empty flex or grid container that screen CSS keeps but print CSS does not collapse.
- Table split across pages: missing
break-inside: avoidon rows or the table itself. - Colours missing:
print-color-adjustdefaults to economy mode in many browsers, dropping backgrounds. - Clipped right edge: fixed pixel widths or screen containers carried into the print stylesheet.
- Wrong paper size:
@pageand driver disagree; the browser scales to fit and distorts the layout.
Debug in this order: print preview first, then PDF export, then the physical printer. Each step rules out one layer of the pipeline.
Cost and operational overhead
Print support is cheap to plan in at the start and expensive to retrofit across dozens of templates. The real cost sits in engineer time chasing browser quirks, plus the support load when a template prints wrong.
What drives the effort is the number of templates, the browser and device variety, the paper sizes in play, and whether you add a server-side PDF pipeline. Maintaining print output also means re-testing whenever the design changes. For a realistic view of what ongoing upkeep involves, see our guide to web application maintenance costs, or our maintenance service.
Security considerations
Treat print output as a data-exfiltration surface. Server-side PDF generation that injects user content can be vulnerable to HTML injection, and printed documents leave paper copies of personal data. Sanitise anything that reaches the print pipeline.
If you generate PDFs from HTML, strip or escape any user-supplied markup before it reaches the engine. Invoices and waybills carry names, addresses and sometimes payment details. Consider who can see the print spool and whether shared printers retain job history. Print is a quiet channel, and quiet channels get overlooked in threat models.
Common mistakes
The mistakes we see most often are hiding elements but not their parents, using pixel widths inside print styles, and testing only on the developer's monitor. Each one produces a paper output the customer notices before the team does.
- Hiding a navigation element but leaving a parent flex container that still reserves space and pushes content down.
- Using pixels for margins and page dimensions, which do not map to physical paper.
- Forgetting
print-color-adjust: exact, so barcodes and brand colours vanish on output. - Testing only at Letter size when customers print A4, or the other way round.
- Adding print CSS after launch and not re-testing every template that uses it.
A realistic scenario
A Kathmandu logistics portal prints delivery waybills from the browser. The first rollout cut the barcode in half because the print stylesheet kept the screen's fixed-width container and the driver used A4 while the CSS assumed Letter.
The team opened print preview, exported a PDF, and saw the clipping immediately. They set @page size to A4, hid the sidebar, applied break-inside: avoid to the waybill card, and exported the barcode as a vector instead of a low-resolution image. The fix took hours, not days, because the failure was reproducible before any customer printed. Our team can review existing print output for the same class of issue — see how we approach custom software development and web design.
Alternatives compared
Three approaches cover most print needs: browser print CSS for close-enough output, server-side PDF for identical controlled documents, and a dedicated reporting engine when print is the product. Choose by how much the paper version is the deliverable.
| Approach | Best for | Trade-offs | Effort to keep running |
|---|---|---|---|
| Browser print CSS | Invoices, receipts, admin exports | Browser and driver differences; not pixel-identical | Low |
| Server-side PDF (headless Chrome, WeasyPrint) | Contracts, regulated documents, labels | Extra service to run, queue and secure; slower | Medium |
| Dedicated reporting engine | High-volume barcode labels, multi-page reports | Learning curve; heavier than most apps need | High |
For WordPress sites that print invoices or packing slips, the same logic applies — many plugins render print views that need the same stylesheet treatment. Our WordPress development service covers that ground.
In short: browsers rebuild the page for paper, not the screen you see. A small @media print stylesheet fixes most day-to-day failures, server-side PDF is the upgrade when output must be identical everywhere, and real-paper testing is the step that catches what previews miss.
People also search for
- What does it cost to keep print support working in a web app?
- Is my invoicing portal a website or a web application?
- Off-the-shelf invoicing versus custom print output
- Where should server-side PDF generation run?
- How is print feature work quoted in a web build?
- Printing from a mobile web view versus a native share sheet
If your web application prints invoices, waybills or reports and the output is starting to cost you support time, our team can review the templates, set up reliable print and PDF output, and hand back something your own team can operate. See our portfolio or contact us to start with a review.












0 comments
Be the first to share your thoughts.
Leave a comment
Replying to — cancel