I have a PDF document that is digitaly signed by an application other than pdfbox. I would now like add an overlay to that digitaly signed PDF using pdfbox. Usually, this would look something like this:
Overlay overlayObj = new Overlay();
PDDocument originalDoc = PDDocument.load(new File(...));
PDDocument overlayDoc = PDDocument.load(new File(...));
overlayObj.setInputPDF(originalDoc);
overlayObj.setAllPagesOverlayPDF(overlayDoc );
Map<Integer, String> ovmap = new HashMap<Integer, String>(); // empty map is a dummy
PDDocument res = overlayObj.overlay(ovmap);
res.save(...);
However, this code generates a new PDF file, thus invalidating the digital signature. It seems that the saveIncremental()
(https://issues.apache.org/jira/browse/PDFBOX-45) may be able to preserve the digital signature.
Is there a way to use saveIncremental()
in combination with overlays? Or is there any other way to overlay a file with a digital signature that preserves the signature?