Hello,
When converting document to PDF/A the resultant document contains invalid XRef table, which contains gap in references. This causes problems in our software when we sign the document several times (then only the last signature is valid and the rest becomes invalid).
Here is what happens during conversion:
XRef table in the original document looks like this:
xref
0 7
0000000000 65535 f
0000000257 00000 n
0000000015 00000 n
0000000345 00000 n
0000000145 00000 n
0000000396 00000 n
0000000441 00000 n
trailer
The conversion creates the following Xref table:
xref
0 15
0000000000 65535 f
0000000018 00000 n
0000000107 00000 n
0000000278 00000 n
0000000330 00000 n
0000000481 00000 n
0000000577 00000 n
0000000727 00000 n
0000000750 00000 n
0000000771 00000 n
0000001040 00000 n
0000001227 00000 n
0000001297 00000 n
0000001521 00000 n
0000001649 00000 n
17 1
0000002323 00000 n
19 2
0000002547 00000 n
0000002609 00000 n
22 4
0000031189 00000 n
0000031970 00000 n
0000032086 00000 n
0000032310 00000 n
trailer
There are 3 gaps (those shorter lines), becasue objects 15, 16, 18, 21 do not exist. According to the PDF specification (section 7.5.4 in ISO32000-1) there should be no gaps in the Xref tables, when put all together:
The cross-reference table (comprising the original cross-reference section and all update sections) shall contain one entry for each object number from 0 to the maximum object number defined in the file, even if one or more of the object numbers in this range do not actually occur in the file.
As this is the first and only XRef table, there shouldn't be any gaps in it. Those gaps make this PDF invalid. When Reader opens PDF it tries to repair it in memory, which is why you can open this PDF in Reader. However, signature validation happens on the original PDF's bytes and it uses the original, not the repaired XRef table, hence the signature validation ends with an error.
When we manually correct the XRef table, the signing with multiple signatures works fine. Here is an example how it can be fixed (by marking those objects as free):
xref
0 26
0000000015 65535 f
0000000018 00000 n
0000000107 00000 n
0000000278 00000 n
0000000330 00000 n
0000000481 00000 n
0000000577 00000 n
0000000727 00000 n
0000000750 00000 n
0000000771 00000 n
0000001040 00000 n
0000001227 00000 n
0000001297 00000 n
0000001521 00000 n
0000001649 00000 n
0000000016 00000 f
0000000018 00000 f
0000002323 00000 n
0000000021 00000 f
0000002547 00000 n
0000002609 00000 n
0000000000 00000 f
0000031189 00000 n
0000031970 00000 n
0000032086 00000 n
0000032310 00000 n
trailer
We are attaching 3 documents:
1) Original document (with one full XRef table) - test_no_sig.pdf
2) Converted document (with gaps) - test_no_sig_converted.pdf
3) Manually fixed document - test_no_sig_converted_corrected.pdf
Here is the conversion code snippet (C#):
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(file);
pdf.Convert(@"e:\aspose1.log.txt", Aspose.Pdf.PdfFormat.PDF_A_1B, Aspose.Pdf.ConvertErrorAction.Delete);
pdf.Save(@"e:\converted_eDane1.pdf");
This is a production problem, so please fix it with higher priority.
Thanks and regards,
Jaro