Class PDFBookmark

  • All Implemented Interfaces:
    Cloneable

    public final class PDFBookmark
    extends Object

    This class describes the Bookmark or Outline part of a PDF document - the "Table of Contents" structure that allows easy navigation through the document.

    Bookmarks are structured like a directory tree, with each node on the tree having zero or more children. The top of the tree is always the document itself.

    Example

    Here's an example of a simple bookmark tree, and the code that creates it.

     +-- Section 1 -+-- SubSection 1.1
     |              |
     |              +-- SubSection 1.2
     |
     +-- Section 2
     
       PDF pdf = new PDF();
    
       // Add the top level bookmarks "Section 1" and "Section 2" to the document.
       List topbookmarks = pdf.getBookmarks();
       PDFBookmark s1 = new PDFBookmark("Section 1", someaction);
       PDFBookmark s2 = new PDFBookmark("Section 2", someaction);
       topbookmarks.add(s1);
       topbookmarks.add(s2);
    
       // Add the bookmarks under "Section 1"
       List s1bookmarks = s1.getBookmarks();
       PDFBookmark s11 = new PDFBookmark("SubSection 1.1", someaction);
       PDFBookmark s12 = new PDFBookmark("SubSection 1.2", someaction);
       s1bookmarks.add(s11);
       s1bookmarks.add(s12);
     

    There is no limit to the number of bookmarks in a PDF document or to the level they are nested. To display the bookmarks when the document is first opened, see the PDF.setOption(java.lang.String, java.lang.Object) method.

    Since:
    1.0
    • Constructor Detail

      • PDFBookmark

        public PDFBookmark​(String name,
                           PDFAction action)
        Create a new bookmark with an initial state of "closed".
        Parameters:
        name - The name of the bookmark as seen by the user. May include Unicode characters.
        action - the action to perform when the bookmark is selected
      • PDFBookmark

        public PDFBookmark​(String name,
                           PDFAction action,
                           boolean open)
        Create a new bookmark and set the initial state to "open" or "closed"
        Parameters:
        name - The name of the bookmark as seen by the user. May include Unicode characters.
        action - The action to perform when the bookmark is selected
        open - Whether the bookmark is open by default
        Since:
        1.0.4
    • Method Detail

      • clone

        protected Object clone()
      • getBookmarks

        public List<PDFBookmark> getBookmarks()
        Return the a List containing this bookmarks children. The list has zero or more elements of type PDFBookmark, and may be altered using any of the standard List methods.
        Returns:
        the list of bookmarks
      • setColor

        public void setColor​(Color c)
        Set the color of the Bookmark. This feature is only available in Acrobat 5 or later (PDF 1.4), but should be safely ignored by earlier viewers.
        Since:
        1.1
      • getColor

        public Color getColor()
        Get the Color of the Bookmark, as set by setColor(java.awt.Color). Returns null if no color is specified.
        Since:
        2.7.8
      • setStyle

        public void setStyle​(boolean italic,
                             boolean bold)
        Set the style of the Bookmark to italic, bold or both. This feature is only available in Acrobat 5 or later (PDF 1.4), but should be safely ignored by earlier viewers.
        Since:
        1.1
      • isBold

        public boolean isBold()
        Return true if the style of the bookmark (as set by setStyle(boolean, boolean) is bold, false otherwise.
        Since:
        2.7.8
      • isItalic

        public boolean isItalic()
        Return true if the style of the bookmark (as set by setStyle(boolean, boolean) is italic, false otherwise.
        Since:
        2.7.8
      • isOpen

        public boolean isOpen()
        Return whether this Bookmark is open.
        Since:
        2.7.8
        See Also:
        setOpen(boolean)
      • setOpen

        public void setOpen​(boolean open)
        Set whether the Bookmark is open
        Since:
        2.7.8
        See Also:
        isOpen()
      • setAction

        public void setAction​(PDFAction action)
        Set the action this bookmark performs when selected
        Parameters:
        action - the action to perform when the bookmark is activated - may be null
        Since:
        1.1.12
      • getAction

        public PDFAction getAction()
        Get the action this bookmark performs when selected
        Returns:
        the action performed when the bookmark is activated - may be null
        Since:
        1.1.12
      • setName

        public void setName​(String name)
        Set the name of this bookmark
        Parameters:
        name - The name of the bookmark as seen by the user. May include Unicode characters.
        Since:
        1.1.12
      • getName

        public String getName()
        Get the name of this bookmark
        Returns:
        the name of the bookmark as seen by the user
        Since:
        1.1.12
      • toString

        public String toString()
      • putLiteral

        public void putLiteral​(String key,
                               String tokens)
        Put a literal token sequnce. For debugging
        Parameters:
        key - the key
        tokens - the token sequence, eg "true" or "/foo" or "[/Foo/Bar]". No refs, just direct objects.