pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: PDDocumentOutline Help
Date Wed, 21 Oct 2015 18:52:38 GMT
Your code works fine with 1.8.11. (Should work with 1.8.10 too) What 
version did you use? Here's what I get:



Tilman

Am 21.10.2015 um 15:00 schrieb Nick Brockett:
> Hi
> Please can somebody explain why the following code executes without error, but the resultant
PDF has nothing added or appended to it.
> I am of course expecting to have a list of page links.
> Thanks in anticipation of help.
>
>     static void addIndex(String filename) throws IOException {
>
>         PDDocument masterDoc = null;
>
>                  try {
>
>                                  File masterFile = new File(filename);
>                                  masterDoc = PDDocument.load(masterFile);
>                                  if( masterDoc.isEncrypted() )
>                                  {
>                                      System.err.println( "Error: Cannot add bookmarks
to encrypted document." );
>                                      System.exit( 1 );
>                                  }
>
>                                                  PDDocumentOutline outline =  new PDDocumentOutline();
>                                                  masterDoc.getDocumentCatalog().setDocumentOutline(
outline );
>                                                  PDOutlineItem pagesOutline = new PDOutlineItem();
>                                                  pagesOutline.setTitle( "All Pages" );
>                                                  outline.appendChild( pagesOutline );
>                                                  @SuppressWarnings("unchecked")
>                                                  List<PDPage> pages = masterDoc.getDocumentCatalog().getAllPages();
>                                       for( int i=0; i<pages.size(); i++ )
>                                       {
>                                           PDPage page = (PDPage)pages.get( i );
>                                           PDPageFitWidthDestination dest = new PDPageFitWidthDestination();
>                                           dest.setPage( page );
>                                           PDOutlineItem bookmark = new PDOutlineItem();
>                                           bookmark.setDestination( dest );
>                                          bookmark.setTitle( "Page " + (i+1) );
>                                           pagesOutline.appendChild( bookmark );
>                                       }
>                                       pagesOutline.openNode();
>                                       outline.openNode();
>                                                  masterDoc.save(filename);
>
>                                  } catch (COSVisitorException e) {
>
>                                                  e.printStackTrace();
>                                  }
>                  finally {
>                                  masterDoc.close();
>
>                  }
> }
>


Mime
View raw message