Remove PDF/A annotatio from PDDocument after merge

I use pdfbox and I want to merge PDF documents. This is not a problem. However, the second file uses the PDF/A annotation. After merging, this annotation is still part of the PDF file.

But I need to sign the document using AcroField, but with the annotation this is not possible.

How can I solve this? Thanks.

Answer

Annotations and PDF/A are two different things. The PDF/A property is in the XMP metadata, however it is likely that it is no longer a valid PDF/A file after merge anyway.

The easiest way to remove the XMP metadata (if you don’t need it) is to call doc.getDocumentCatalog().setMetadata(null).

If a more fine-tuned approach is needed, one can combine the ExtractMetadata.java example (gets the xmp metadata) with the CreatePDFA.java example (saves the metadata) and try to call xmp.removeSchema(xmp.getPDFExtensionSchema()).