OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

Merging two PDF/A files using PdfCopy does not generate PDF/A compliant resultant file

Open bk1991 opened this issue 2 years ago • 1 comments

If we try to merge two or more PDF/A compliant files using PdfCopy, then generated resultant PDF file is not PDF/A complaint. Validator shows below error message - https://www.pdf-online.com/osa/validate.aspx

File: mergeusing_openPDF.pdf Compliance: pdfa-1a Result: Document does not conform to PDF/A. Details: Validating file "mergeusing_openPDF.pdf" for conformance level pdfa-1a The key MarkInfo is required but missing. The key StructTreeRoot is required but missing. The document does not conform to the requested standard. The document doesn't provide appropriate logical structure information. The document does not conform to the PDF/A-1a standard. Done.

After debugging we found that, PdfCopy is overriding the getCatalog() method and which is hiding the PdfWriter's implementation of this method which has below lines of code - catalog.put(PdfName.STRUCTTREEROOT, structureTreeRoot.getReference()); PdfDictionary mi = new PdfDictionary(); mi.put(PdfName.MARKED, PdfBoolean.PDFTRUE);

hence the resultant document is missing this metadata which is causing the validation failure. ExampleMerge.txt

Here is related Stack Overflow issue - https://stackoverflow.com/questions/73870485/how-to-merge-multiple-pdf-a-files-and-generate-new-pdf-a-in-java

bk1991 avatar Sep 28 '22 13:09 bk1991

Attaching the input PDFA files and resultant merged PDF files which shows the PDFA compliance failure Merged_PDFA_files.zip

bk1991 avatar Sep 28 '22 14:09 bk1991