OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

Hidden layers of pdf is visible when processed with openpdf

Open oogycockroach opened this issue 3 months ago • 3 comments

Hi, I'm Ramani Sankar and I'm trying to apply watermark on a pdf which contains multiple visible and hidden layers using openpdf.jar (version: 2.0.3). The output created by the jar makes all the layers in the pdf to be visible which is a bug. Output pdf should not show the hidden layers. productcode.java

Expected output : Image

The output we got shows the hidden "Technical info" layer to be visible :

Image

oogycockroach avatar Nov 13 '25 04:11 oogycockroach

Most likely the problem does not occur in the watermarking step of your code but in the second step where you create a copy of the document pages.

mkl-public avatar Nov 13 '25 07:11 mkl-public

What can be the solution to it? The second step is mandatory and cannot be removed from our product

oogycockroach avatar Nov 14 '25 05:11 oogycockroach

The issue occurs because PdfCopy does not preserve the source document’s /OCProperties dictionary, so hidden OCG layers become visible after copying. PdfStamper keeps the OCG configuration intact, but PdfCopy rebuilds the catalog without copying the layer settings. The workaround is to subclass PdfCopy and manually copy /OCProperties into getExtraCatalog(), or to skip the PdfCopy phase if only watermarking is needed. A proper library fix would be to automatically copy the /OCProperties dictionary when building the catalog in PdfCopy. This ensures that hidden layers remain hidden and the original layer configuration is preserved in the output.

andreasrosdal avatar Nov 14 '25 18:11 andreasrosdal