How can I make Edge honor a custom CSS page size when printing to PDF?

August 4, 2026 4 answers
Asked by MellowPine42
I'm building a browser-only web app that uses window.print() to create PDF pages for self-publishing. The page uses a print stylesheet such as @page { size: 5.5in 8.5in; margin: 0; }, but Edge's print dialog ignores the CSS-defined dimensions and uses the paper size selected in its dropdown instead. The content itself is correct, but the resulting PDF has incorrect extra margins along the right and bottom edges. Chrome handles the custom size correctly. Is there a workaround that keeps using window.print(), or is this an Edge-specific bug?

Answers

QuietHarbor19
If you need consistent output across browsers, avoid the native print dialog and generate the PDF directly. Puppeteer or Playwright can create PDFs with explicit width, height, and margin values, which removes the operating system dialog from the process and gives you predictable dimensions.
Reply to this answer
CobaltMango7
This appears to be a Chromium-based print-dialog quirk that was particularly noticeable in Edge: the dialogโ€™s selected paper size could override the @page size. A recent Edge update may have fixed it, so updating the browser is worth trying before changing the implementation.

MellowPine42: That seems to have solved it. After the latest Edge update, the browser now honors the custom CSS page size, so the extra borders are gone.

Reply to this answer
AmberRook31
For a branded or highly consistent document, rendering the PDF with a headless browser on a server is usually the most reliable approach. Itโ€™s more infrastructure than window.print(), though, and may be unnecessary if the Edge update has already corrected the issue.
Reply to this answer
SilverKite_58
A client-side HTML-to-PDF library is another possibility because it writes the page dimensions directly into the PDF instead of depending on browser print CSS. However, libraries in that category can produce very large files or PDFs that fail publishing-platform requirements, so they may not be a good fit here.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions