Skip to content

fix(pdf): BEHIND_CONTENT watermark opacity no longer bleeds into page content#159

Merged
DemchaAV merged 1 commit into
developfrom
fix/watermark-alpha-leak
Jun 11, 2026
Merged

fix(pdf): BEHIND_CONTENT watermark opacity no longer bleeds into page content#159
DemchaAV merged 1 commit into
developfrom
fix/watermark-alpha-leak

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Problem

A BEHIND_CONTENT watermark renders through a PREPEND content stream. The renderer set the watermark opacity via ExtGState there without a q/Q pair — and PDFBox's resetContext flag only isolates APPEND streams. The low alpha constant leaked into the original page stream, washing out the entire page (everything rendered at the watermark's opacity, except elements that set their own alpha).

Since DocumentWatermark defaults to layer = BEHIND_CONTENT, every document using a default watermark was affected. Found while verifying the feature-catalog render: the whole page was ghosted except the translucency demo chips.

Fix

PdfWatermarkRenderer.apply now wraps the watermark drawing in saveGraphicsState() / restoreGraphicsState().

Tests

  • New PdfWatermarkStateIsolationTest: renders a solid navy shape under a BEHIND_CONTENT watermark at opacity 0.05, asserts the shape centre samples at full strength (pixel check) and the watermark still carries its low-alpha ExtGState. Verified the test fails on the unfixed renderer and passes with the fix.
  • Full canonical suite green.

… content

The watermark renderer set its low-alpha graphics state inside a
prepended content stream without a save/restore pair. PDFBox's
resetContext flag only isolates APPEND streams, so the alpha constant
leaked into the original page stream and washed out every element on
the page. Wrap the watermark drawing in q/Q.

Regression test renders a solid shape under a BEHIND_CONTENT watermark
and asserts the fill samples at full strength while the watermark keeps
its own low-alpha ExtGState.
@DemchaAV DemchaAV merged commit b02c82f into develop Jun 11, 2026
11 checks passed
@DemchaAV DemchaAV deleted the fix/watermark-alpha-leak branch June 11, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant