A further problem

Even this is not perfect. Consider the example:


\begin{lstlisting}
2 0 obj
/Complex
endobj
1 0 obj
<<
/Type /Catalog
/Pages 3 ...
... [ (Even more) 2 0 R ]
>>
endobj
...
trailer
<<
/Root 1 0 R
>>
\end{lstlisting}

Suppose we want to copy both Root/Example and Root/Example2 between files. If we read the first of these, and write it, it will cause object 2 to be copied to the new file (as a new object, 99 say). When we read the second one, and write that, it will cause object 2 to be copied into the second file again (as object 100 perhaps).

In the example above, with the object consisting of a single name this duplication may not matter, but when you consider that objects might be dictionaries with lots of contents, or even streams with many megabytes of data attached, the problem becomes clear.

The solution to this is to use a pdf_graft_map.