Hidden layers of pdf is visible when processed with openpdf
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 :
The output we got shows the hidden "Technical info" layer to be visible :
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.
What can be the solution to it? The second step is mandatory and cannot be removed from our product
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.