Michael Marsella wrote:

> if there is
> a way to modify the page contents stream of a PDF file and have that
> saved back to the same file.

PoDoFo cannot save changes to an existing PDF file yet. To do so, it
would need to support tracking object generations and the writing of
multi-part xref tables with secondary trailers etc, which it does not
yet (though it wouldn't actually be that big a job to add).

You probably don't actually want to do this anyway, since it means that
every content stream you modify is actually included in the file twice -
the superceded original in the unmodified original part of the file,
followed by the superceding new version in the appended changes.

What most tools do when they "save" a PDF is actually to write a new
copy to a temporary file, then replace the original with it using a
filesystem level move operation (which is atomic in most file systems).
If they crash mid-way through save, etc, you don't lose the file, and
they can read from the original as they write to the new one.

That's how you do it with PoDoFo. If you attempt to just overwrite the
original PDF, BAD THINGS WILL HAPPEN since PoDoFo will be attempting to
read content stream data from a file you just truncated to write to it.

PoDoFo is perfectly capable of replacing a content stream with a new
version that contains your changes and saving the altered PDF document
to a new file, which you can then replace the original file with.

> Specifically I want to add marked content tags to each item in the
> content stream.

That should be no problem, though you will have to do much of the work
yourself. PoDoFo only really provides support for reading a content
stream as a sequence of PDF data type objects; it leaves the
interpretation of the stream and its higher level structure to you.

--
Craig Ringer

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to