Aaron J Weber wrote:

This has got to be an easy one for all you iText "Pros" out there!
I'm looking at the "iText by Example", Concatenate.java file. What I think would be stellar would be if we could (optionally) add a bookmark at the root of the outline that has a destination of the first page of the concatenated document. Some of the logic would change a little (i.e. the SimpleBookmark list may never be null if you're prepending it to that list). Anyway, can anyone give me an example of how I could mod that code to simply insert a bookmark as I concat each file in the array?

Read the following example,
try to understand what happens
and adapt it to your needs:

ArrayList bookmarks = new ArrayList();
PdfReader reader = new PdfReader("HelloWorld1.pdf");
Document document = new Document(reader.getPageSizeWithRotation(1));
PdfCopy copy = new PdfCopy(document, new FileOutputStream("HelloWorldCopyBookmarks.pdf"));
document.open();
copy.addPage(copy.getImportedPage(reader, 1));
bookmarks.addAll(SimpleBookmark.getBookmark(reader));
reader = new PdfReader("HelloWorld2.pdf");
copy.addPage(copy.getImportedPage(reader, 1));
List tmp = SimpleBookmark.getBookmark(reader);
SimpleBookmark.shiftPageNumbers(tmp, 1, null);
bookmarks.addAll(tmp);
reader = new PdfReader("HelloWorld3.pdf");
copy.addPage(copy.getImportedPage(reader, 1));
tmp = SimpleBookmark.getBookmark(reader);
SimpleBookmark.shiftPageNumbers(tmp, 2, null);
bookmarks.addAll(tmp);
copy.setOutlines(bookmarks);
document.close();

If null is returned (if no bookmarks are present),
you can create bookmarks like this:
HashMap map = new HashMap();
map.put("Title", "Title Page");
map.put("Action", "GoTo");
map.put("Page", "1 Fit");
list.add(0, map);

br,
Bruno


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to