Skip to main content

I Want to Fix Repeated Background-Filled Blank Pages in Screen Mode PDFs

Updated over a month ago

You’re converting an HTML page to PDF using screen mode, but you notice repeated blank pages filled with background color or images. These extra pages are unnecessary and affect the final document layout.

Why This Happens

When using "mediaType": "screen" in the HTML-to-PDF conversion, the system renders the page as it appears in a browser screen (not print preview).

"profiles": "{\"mediaType\":\"screen\"}"

This means screen-specific CSS (including full-page background styles) gets applied.

If your HTML includes information blocks of a fixed size and also applies page-level backgrounds, the converter might insert extra pages filled with background only. That’s because after an information block ends, the PDF engine breaks the page but still fills the rest of that page with the defined background—creating a blank, styled page.

How to Fix It

To fix this, do the following.

Set a Custom Paper Size

The solution here is to adjust the page size to match the exact dimensions of your content block. This avoids the extra space that leads to background-filled blanks.

Example Fix

If your content block is 625×880px, use this profiles setting in your HTML-to-PDF API call:

"profiles": "{\"paperSize\":\"625px 880px\", \"mediaType\":\"screen\"}"

This tells the converter to render the PDF page using a size that fits the block exactly, preventing the extra spacing and therefore the repeated background pages.

Helpful Tips

  • Use "mediaType": "screen" only when you need CSS and visual styling meant for on-screen display.

  • Always match the custom paper size to your content block dimensions.

  • If unsure of exact dimensions, inspect your HTML or test with sample values.

  • Consider using "async": true for large documents and monitor status if needed.

Did this answer your question?