My requirement is to prefix a PDF generated by some other process with a single 'cover page'.
I've written a relatively simple Ant task to concatenate a list of PDF documents, and this works well, but the TOC is not preserved in the process. By TOC I mean ..
Ideally, both TOCs would be preserved, and adjusted for their new offsets, but I can see no means of reading or writing the TOC (the left hand one) in the iText API. Can anyone?
M.
I'm the author of the book about iText and in the context of this book, I've written an example that explains how to concatenate PDFs while preserving the bookmarks (aka the outline tree). You can find this example here. As you can see, you need the SimpleBookmark
object to extract the bookmarks from the existing documents. Make sure that you shift the page numbers, or your links will point at the wrong pages. Finally add the new ArrayList<HashMap<String, Object>>
to the PdfCopy
object using the setOutlines()
method.
Once again, we've found proof that reading documentation saves time ;-)