System.err.println( "Error: Cannot add bookmarks to encrypted document." );
System.exit( 1 );
}
PDDocumentOutline outline = new PDDocumentOutline();
document.getDocumentCatalog().setDocumentOutline( outline );
PDOutlineItem pagesOutline = new PDOutlineItem();
pagesOutline.setTitle( "All Pages" );
outline.appendChild( pagesOutline );
int pageNum = 0;
for( PDPage page : document.getPages() )
{
pageNum++;
PDPageFitWidthDestination dest = new PDPageFitWidthDestination();
dest.setPage( page );
PDOutlineItem bookmark = new PDOutlineItem();
bookmark.setDestination( dest );
bookmark.setTitle( "Page " + pageNum );
pagesOutline.appendChild( bookmark );
}
pagesOutline.openNode();
outline.openNode();