Prashanth Udupa wrote:

> Actually, I was trying to update an existing PDF document using a
> structure like this.
> 
> PdfDocument doc;
> doc.Load("someDoc.pdf");
> /// do all the updates
> doc.Write("someDoc.pdf"); // <- Crash.

Yep, that's a nasty trap. There's not much PoDoFo can do about it,
though, since it relies on the use of PdfFileStream etc for efficient
operation - and simply _can_ _not_ overwrite documents in place.

It'd be nice to support opening the file for append and writing a new
document segment with incremented generation number objects, a new xref
for the changed objects, and a new trailer (especially since this makes
it possible to annotate signed documents). It's not supported yet,
though, and would probably have to use a different interface.

That said, it'd be nice to detect this issue. We can't do so reliably,
though, simply because most platforms offer absolutely no way to tell if
two paths refer to the same file object. It's not always even possible
to rely on unique inode numbers etc, and trying that sort of thing
causes portability problems.

On the other hand, PdfFileStream clearly needs to check the error state
on the file stream and throw rather than crashing. That way if you make
this kind of mistake it'll at least produce a more informative result -
"PdfFileStream: unexpected EOF when reading (file truncated?)" or
similar. I'll see what I can do in this regard.

I've run into this issue with PoDoFoBrowser, and haven't found a better
solution than writing to a temp file then moving it back over the
original when writing finishes. Appending would often be preferable,
especially for large files.

> Then I noticed the comments in the code and realized my mistake. I
> wrote a PdfOutputStream subclass to fix this problem and now the
> output works!

Great. I take it your subclass just writes to a temporary then moves it
back over the original on close?

--
Craig Ringer

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to