From 4647acbe3c2266e9add3415a06f4c5e84d49f814 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 29 Jul 2017 09:25:25 -0400 Subject: Clarify documentation on copyForeignObject (fixes #69) Be explicit about the need to keep the source QPDF object around. --- manual/qpdf-manual.xml | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'manual') diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 18abc013..4fde831a 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -1983,24 +1983,26 @@ outfile.pdf Version 3.0 of qpdf introduced the ability to copy objects into a QPDF object from a different QPDF object, which we refer to as - foreign objects. This allows arbitrary - merging of PDF files. The qpdf command-line - tool provides limited support for basic page selection, including - merging in pages from other files, but the library's API makes it - possible to implement arbitrarily complex merging operations. The - main method for copying foreign objects is - QPDF::copyForeignObject. This takes an + foreign objects. This allows arbitrary + merging of PDF files. The &ldqo;from&rdqo; + QPDF object must remain valid after the + copy as discussed in the note below. The qpdf + command-line tool provides limited support for basic page + selection, including merging in pages from other files, but the + library's API makes it possible to implement arbitrarily complex + merging operations. The main method for copying foreign objects is + QPDF::copyForeignObject. This takes an indirect object from another QPDF and copies it recursively into this object while preserving all object - structure, including circular references. This means you can add - a direct object that you create from scratch to a + structure, including circular references. This means you can add a + direct object that you create from scratch to a QPDF object with QPDF::makeIndirectObject, and you can add an indirect object from another file with - QPDF::copyForeignObject. The fact that + QPDF::copyForeignObject. The fact that QPDF::makeIndirectObject does not automatically detect a foreign object and copy it is an explicit - design decision. Copying a foreign object seems like a + design decision. Copying a foreign object seems like a sufficiently significant thing to do that it should be done explicitly. @@ -2012,6 +2014,14 @@ outfile.pdf automatically distinguishes between indirect objects in the current file, foreign objects, and direct objects. + + Please note: when you copy objects from one + QPDF to another, the source + QPDF object must remain valid until you + have finished with the destination object. This is because the + original object is still used to retrieve any referenced stream + data from the copied object. + Writing PDF Files -- cgit v1.2.3-54-g00ecf