com.aspose.pdf.facades

Class PdfBookmarkEditor

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IFacade, ISaveableFacade


    public final class PdfBookmarkEditor
    extends SaveableFacade

    Represents a class to work with PDF file's bookmarks including create, modify, export, import and delete.

    • Constructor Detail

      • PdfBookmarkEditor

        public PdfBookmarkEditor()

        Initializes new PdfBookmarkEditor object.

      • PdfBookmarkEditor

        public PdfBookmarkEditor(IDocument document)

        Initializes new PdfBookmarkEditor object on base of the document.

        Parameters:
        document - Pdf document.
    • Method Detail

      • createBookmarks

        public void createBookmarks()

        Creates bookmarks for all pages.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.createBookmarks();
         editor.save("example_out.pdf");
         
      • createBookmarkOfPage

        public void createBookmarkOfPage(String bookmarkName,
                                int pageNumber)

        Creates bookmark for the specified page.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.createBookmarkOfPage("bookmark for page 1", 1);
         editor.save("example_out.pdf");
         
        Parameters:
        bookmarkName - The specified bookmark name.
        pageNumber - The specified desination page.
      • createBookmarks

        public void createBookmarks(Bookmark bookmark)

        Creates the specified bookmark in the document. The method can be used for forming nested bookmarks hierarchy.


         
         
          PdfBookmarkEditor editor = new PdfBookmarkEditor();
          editor.bindPdf("example.pdf");
          Bookmark bm1=new Bookmark();
          bm1.setPageNumber(1);
          bm1.setTitle("First child");
                Bookmark bm2=new Bookmark();
                bm2.setPageNumber(2);
          bm2.setTitle("Second child");
          Bookmark bm=new Bookmark();
          bm.setAction=(GoTo");
          bm.setPageNumber(1);
          bm.setTitle("Parent");
          Bookmarks bms=new Bookmarks();
          bms.add(bm1);
          bms.add(bm2);
          bm.setChildItem(bms);
          editor.setCreateBookmarks(bm);
          editor.save("example_out.pdf");
          
        Parameters:
        bookmark - The bookmark will be added to the document.
      • createBookmarks

        public void createBookmarks(Color color,
                           boolean boldFlag,
                           boolean italicFlag)

        Create bookmarks for all pages with specified color and style (bold, italic).


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.createBookmarks(System.Drawing.Color.Red, true, true);
         editor.save("example_out.pdf");
         
        Parameters:
        color - The color of title.
        boldFlag - The flag of bold attribution.
        italicFlag - The flag of italic attribution.
      • createBookmarkOfPage

        public void createBookmarkOfPage(String[] bookmarkName,
                                int[] pageNumber)

        Creates bookmarks for the specified pages.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.createBookmarkOfPage("bookmark for page 1", 1);
         editor.save("example_out.pdf");
         
        Parameters:
        bookmarkName - Bookmarks title array.
        pageNumber - Bookmarks desination page array.
      • deleteBookmarks

        public void deleteBookmarks()

        Deletes all bookmarks of the PDF document.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.deleteBookmarks();
         editor.save("example_out.pdf");
         
      • deleteBookmarks

        public void deleteBookmarks(String title)

        Deletes the bookmark of the PDF document.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.deleteBookmarks("existing bookmark title");
         editor.save("example_out.pdf");
         
        Parameters:
        title - The title of bookmark deleted.
      • modifyBookmarks

        public void modifyBookmarks(String sTitle,
                           String dTitle)

        Modifys bookmark title according to the specified bookmark title.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.modifyBookmarks("existing bookmark title", "new bookmark title");
         editor.save("example_out.pdf");
         
        Parameters:
        sTitle - Source bookmark title.
        dTitle - Modified bookmark title.
      • extractBookmarks

        public Bookmarks extractBookmarks()

        Extracts bookmarks of all levels from the document.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         Bookmarks bms = editor.ExtractBookmarks();
         for(Bookmark bm : bms)
             System.out.println(bm.Title);
         
        Returns:
        The bookmarks collection of all bookmarks that exist in the document.
      • extractBookmarks

        public Bookmarks extractBookmarks(boolean upperLevel)

        Extracts bookmarks of all levels from the document.

        Parameters:
        upperLevel - If true, extracts only upper level bookmarks. Else, extracts all bookmarks recursively.
        Returns:
        List of extracted bookmarks.
      • extractBookmarks

        public Bookmarks extractBookmarks(String title)

        Extracts the bookmarks with the specified title.


         
         
          PdfBookmarkEditor editor = new PdfBookmarkEditor();
          editor.bindPdf("example.pdf");
                Bookmarks bms = editor.ExtractBookmarks("Title");
          for(Bookmark bm : (Iterable<Bookmark>)bms)
              System.out.println(bm.Title);
          
        Parameters:
        title - Extracted item title.
        Returns:
        Bookmark object collection has items with the same title.
      • extractBookmarks

        public Bookmarks extractBookmarks(Bookmark bookmark)

        Extracts the children of a bookmark with a title like in specified bookamrk.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         Bookmark bookmark = new Bookmark();
         bookmark.setTitle ( "Title");
         Bookmarks bms = editor.ExtractBookmarks(bookmark);
         for(Bookmark bm : (Iterable<Bookmark>)bms)
             System.out.println(bm.Title);
         
        Parameters:
        bookmark - The specified bookamrk.
        Returns:
        Bookmark collection with child bookmarks.
      • extractBookmarksToHTML

        @Deprecated
        public void extractBookmarksToHTML(String pdfFile,
                                             String cssFile)
        Deprecated. 

        Exports bookmarks to HTML file.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.extractBookmarksToHTML("example.pdf", null);
         
        Parameters:
        pdfFile - The PDF file which bookmarks will be exported.
        cssFile - The CSS file to display HTML file, can be null.
      • exportBookmarksToXML

        public void exportBookmarksToXML(String xmlFile)

        Exports bookmarks to XML file.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.exportBookmarksToXML("bookmarks.xml");
         
        Parameters:
        xmlFile - The output XML file.
      • exportBookmarksToXML

        public void exportBookmarksToXML(OutputStream output)

        Exports bookmarks to XML stream.

        Parameters:
        output - Output stream where data will be stored.
      • importBookmarksWithXML

        public void importBookmarksWithXML(String xmlFile)

        Imports bookmarks to the document from XML file.


         
         
         PdfBookmarkEditor editor = new PdfBookmarkEditor();
         editor.bindPdf("example.pdf");
         editor.importBookmarksWithXML("bookmarks.xml");
         editor.save("example_out.pdf");
         
        Parameters:
        xmlFile - The XML file containing bookmarks list.
      • importBookmarksWithXML

        public void importBookmarksWithXML(InputStream stream)

        Imports bookmarks to the document from XML file.

        Parameters:
        stream - Stream with bookmarks data.
      • exportBookmarksToHtml

        public static void exportBookmarksToHtml(String inPdfFile,
                                 String outHtmlFile)

        Exports bookmarks to HTML file.


         
         
         PdfBookmarkEditor.extractBookmarksToHTML("example.pdf", "bookmarks.html");
         
        Parameters:
        inPdfFile - Input PDF file which bookmarks will be exported.
        outHtmlFile - Output HTML file
      • close

        public void close()

        Close the instance of PdfBookmarkEditor and release the resources.

        Specified by:
        close in interface IFacade
        Overrides:
        close in class Facade