Graphics Programs Reference
In-Depth Information
To include pages from a file at two or more distinct points in the output, we can asso-
ciate handles with each file by writing, for example A=input.pdf , and refer to those
handles when giving the page ranges.
A1 A B The first page of document A (duplicated as a cover page), then the whole
of documents A and B .
A4-50oddD Odd pages of file labeled A between 4 and 50, rotated by 180°.
For example:
pdftk A=file.pdf B=file2.pdf A1 A B output out.pdf
What Happens when Files are Merged
To perform a simple merge of PDF files in the manner of pdftk , the following steps
might be performed:
1. Read each file into memory and create a graph of PDF objects, possibly lazily (i.e.,
parsing objects on demand, since not all of them will be needed if only certain pages
are included).
2. Renumber the objects in the object graphs so they are mutually exclusive i.e., 1...p,
p+1...q, q+1...r etc.
3. Put all these PDF objects into a new object graph.
4. Create a new page tree, containing the required combination of page objects from
the original files.
5. Create a new trailer dictionary and root object, linking to the new page tree.
6. Write the new document to a file.
A fully functioning merge would also need to:
• Trim references to pages no longer in the document due to the use of a page range.
Were this not done, a single reference to a page which is not in the output can
result in the inclusion of all of the objects from that page, bloating the output.
• Remove duplicate font definitions. Often, files to be merged come from the same
source, and share content like fonts. These can be deduplicated to save space.
• Combine the other parts of the file—bookmarks, destinations, forms and so on.
Generally speaking, data which is strictly per-page survives automatically, but
document-wide data needs specific merging support.
• Making decisions on where to take metadata and PDF version numbers from (for
example, using the highest PDF version number amongst the inputs and taking the
metadata from the first given file).
Search WWH ::




Custom Search