I have created a tool to split a PDF by bookmark levels (depth).
My Example PDF:
Level 1
Level 11
Level 111
Level 112
Level 12
Level 13
Level 2
Level 21
Level 211
Level 22
When I split the PDF at the 2nd level I get the following files:
Files:
======
Level 11.pdf
Level 12.pdf
Level 13.pdf
Bookmark for first PDF
----------------------
Level 1
Level 11
Level 111
Level 112
Files
=====
Level 21.pdf
Level 22.pdf
Bookmark Bookmark for first PDF
-------------------------------
Level 2
Level 21
Level 211
To set the bookmarks in the splitted Output files I use the following Code:
if (SetBookmarks == true && bookmarks.isEmpty() ==
false) {
int pageRange1 [] = new int[2];
pageRange1[0] = 1;
pageRange1[1] =
Integer.parseInt(BM_page.get(i).toString()) - 1;
int pageRange2 [] = new int[2];
pageRange2[0] = end;
pageRange2[1] = reader.getNumberOfPages();
//New Bookmarklist = Bookmarklist from Source PDF
List<HashMap> Newbookmarks =
SimpleBookmark.getBookmark(reader);
// Remove Bookmarks from missing Pages (PagerRange
after OutputPages)
SimpleBookmark.eliminatePages(Newbookmarks,pageRange2);
//Check for 1th pate
if (pageRange1[1] != 0) {
// Remove PageRange before OuptutPages
SimpleBookmark.eliminatePages(Newbookmarks,pageRange1);
//Shift Page-Numbers
SimpleBookmark.shiftPageNumbers(Newbookmarks,
-pageRange1[1], null);
}
//Set bookmarks in new PDF
writer.setOutlines(Newbookmarks);
//Show TreeView in PDF-Reader
writer.setViewerPreferences(
PdfWriter.PageModeUseOutlines);
}
No I am searching for a way to remove all Bookmarks less then level x (for
Example < 2) so that I get the following result:
Files:
======
Level 11.pdf
Level 12.pdf
Level 13.pdf
Bookmark for first PDF
----------------------
Level 11
Level 111
Level 112
Files
=====
Level 21.pdf
Level 22.pdf
Bookmark Bookmark for first PDF
-------------------------------
Level 21
Level 211
Hope that someone can help me.
Carsten
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php