Am 25.01.2013 20:26, schrieb Charles Smith:
There's zero documentation on this. How does saveIncremental work? I've
tried loading a document I created, reading it in, adding a page, and then
calling saveIncremental.... and nothing happens. The file is unchanged.
Also, why are both an input and output stream required?
I've looked through the code, but there aren't any comments and I will need
a better understanding of how everything works together before I can make
heads or tails of it.
Charles.
Hi Carles,
this is a bit complicated. The saveIncremental was designed for signing
purpose only. The class COSWriter which do the write work needs to know
which objects need to be wrote in the increment. The COSWriter starts
with the document catalog and write the objects recursive with all
references. If a object was already written, the COSWriter skip it. To
the fact that each document has a document catalog, the writer see that
this object exist, skip it and stop his work immediatly.
For writting a new page, you need to know which way the COSWriter need
to go to find your new page (and the not existing objects). If you mark
all objects on that way to your new page with the flag
.needToBeUpdate(true) the COSWriter will start writting the old and the
new objects. So you need to give the COSWriter a hint. Also altered
objects need to be marked for update. You can look at the sourcecode of
PDDocument#addSignature(...) if you want to know how to do it.
For real incremental update support, the COSWriter need to be replaced
with one that does not work recursive.
The streams for the incremental update method are needed to write a
signature and a byterange after the document was wrote complet on the
disk. This hack was only need for documents that was loaded with the
PDDocument.load(InputStream) method. Due to the fact that the PDDocument
does not store the loaded document as File, this will help the signature
implementation to attach the signature and byterange after updating.
I hope I could help you understanding this problem.
Best regards
Thomas