Hi!
I'm having a problem when appending documents, and building an outline. I have
a "main" document and one or more "attachment" documents. These documents are
appended to each other. When creating the new document I want to build a
outline where the main document is root, and the attachment documents are
children of this root.
The problem I am having is that the outline is shown correctly, but the outline
items for the attachments does not seem to have a destination.
Below is my code
-------------
PDDocument pdf = PDDocument.load(file);
PDDocumentCatalog documentCatalog = pdf.getDocumentCatalog();
PDDocumentOutline outline = new PDDocumentOutline();
PDOutlineItem outlineRoot = new PDOutlineItem();
outlineRoot.setTitle(contentTitle);
outlineRoot.setDestination((PDPage) documentCatalog.getAllPages().get(0));
outline.appendChild(outlineRoot);
PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
for(File attachmentFile : attachments){
PDDocument attachment = PDDocument.load(attachmentFile);
pdfMergerUtility.appendDocument(pdf, attachment);
PDDocumentCatalog attachmentDocumentCatalog =
attachment.getDocumentCatalog();
PDDocumentOutline attachmentOutline =
attachmentDocumentCatalog.getDocumentOutline();
PDOutlineItem attachmentOutlineItem = attachmentOutline.getFirstChild();
attachmentOutlineItem.setDestination((PDPage)
attachmentDocumentCatalog.getAllPages().get(0));
outlineRoot.appendChild(attachmentOutlineItem);
}
documentCatalog.setDocumentOutline(outline);
---------
Does anyone see anything wrong with this?
--
Marvin B. Lillehaug