I have been writing some code in Typescript to compute incremental update of two PDFs, because the library we use doesn't support this (pdf-lib)
The process is as follow:
- Load PDF to pdf-lib
- Make modifications (in my case: write a digital signature)
- Write the new file
- Compare the two files object-by-object and put the difference at the end of the original file as an incremental update, then write the xref/trailer.
My code works great, until I tested a PDF with an XREF table in an object stream. In this case, Adobe Reader complains with:
From that I see, the format of XREF as streams is different, however my code always writes a regular XREF table at the end.
I have uploaded the original and modified PDF here: http://www.wikiupload.com/JPM2J1I9H3HD4JP
The important bits are:
- The original file ends with an XREF stream:
8 0 obj ... endobj startxref 116
- The incremental update I got ends with:
xref 0 1 0000000000 65535 f ... trailer << /Size 79 /Root 21 0 R /Info 19 0 R /Prev 116 >> startxref 152863 %%EOF
My question is: if the original PDF contains XREF streams, should the incremental update also write the XREF in the same object as replacement? Or is there a way to make the two methods work together? Or is the problem unrelated?