com.aspose.words

Class BookmarksOutlineLevelCollection

  • java.lang.Object
    • com.aspose.words.BookmarksOutlineLevelCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class BookmarksOutlineLevelCollection 
    extends java.lang.Object

A collection of individual bookmarks outline level.

Key is a case-insensitive string bookmark name. Value is a int bookmark outline level.

Bookmark outline level may be a value from 0 to 9. Specify 0 and Word bookmark will not be displayed in the document outline. Specify 1 and Word bookmark will be displayed in the document outline at level 1; 2 for level 2 and so on.

Example:

Shows how to set outline levels for bookmarks.
// Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
// such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
builder.startBookmark("Bookmark 1");
builder.writeln("Text inside Bookmark 1.");

builder.startBookmark("Bookmark 2");
builder.writeln("Text inside Bookmark 1 and 2.");
builder.endBookmark("Bookmark 2");

builder.writeln("Text inside Bookmark 1.");
builder.endBookmark("Bookmark 1");

builder.startBookmark("Bookmark 3");
builder.writeln("Text inside Bookmark 3.");
builder.endBookmark("Bookmark 3");

// We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
// of space proportional to the indent level in a SaveOptions object
// Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
// This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();

outlineLevels.add("Bookmark 1", 1);
outlineLevels.add("Bookmark 2", 2);
outlineLevels.add("Bookmark 3", 3);

Assert.assertEquals(outlineLevels.getCount(), 3);
Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
Assert.assertEquals(outlineLevels.get(0), 1);
Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);

// We can remove two elements so that only the outline level designation for "Bookmark 1" is left
outlineLevels.removeAt(2);
outlineLevels.remove("Bookmark 2");

// We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
// and get numbered in succession along that order
// Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
outlineLevels.add("Bookmark 2", 5);
outlineLevels.add("Bookmark 3", 9);

// Save the document as a .pdf and find links to the bookmarks and their outline levels
doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);

// We can empty this dictionary to remove the contents table
outlineLevels.clear();

Constructor Summary
 
Property Getters/Setters Summary
intgetCount()
Gets the number of elements contained in the collection.
intget(int index)
void
set(intindex, intvalue)
           Gets or sets a bookmark outline level at the specified index.
intget(java.lang.String name)
void
set(java.lang.Stringname, intvalue)
           Gets or a sets a bookmark outline level by the bookmark name.
 
Method Summary
voidadd(java.lang.String name, int outlineLevel)
Adds a bookmark to the collection.
voidclear()
Removes all elements from the collection.
booleancontains(java.lang.String name)
Determines whether the collection contains a bookmark with the given name.
intindexOfKey(java.lang.String name)
Returns the zero-based index of the specified bookmark in the collection.
java.util.Iterator<java.util.Map.Entry<java.lang.String, int>>iterator()
voidremove(java.lang.String name)
Removes a bookmark with the specified name from the collection.
voidremoveAt(int index)
Removes a bookmark at the specified index.
 

    • Constructor Detail

      • BookmarksOutlineLevelCollection

        public BookmarksOutlineLevelCollection()
    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Gets the number of elements contained in the collection.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
      • get/set

        public int get(int index) / public void set(int index, int value)
        
        Gets or sets a bookmark outline level at the specified index.
        Parameters:
        index - Zero-based index of the bookmark.
        Returns:
        The outline level of the bookmark. Valid range is 0 to 9.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
      • get/set

        public int get(java.lang.String name) / public void set(java.lang.String name, int value)
        
        Gets or a sets a bookmark outline level by the bookmark name.
        Parameters:
        name - Case-insensitive name of the bookmark.
        Returns:
        The outline level of the bookmark. Valid range is 0 to 9.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
    • Method Detail

      • add

        public void add(java.lang.String name, int outlineLevel)
        Adds a bookmark to the collection.
        Parameters:
        name - The case-insensitive name of the bookmark to add.
        outlineLevel - The outline level of the bookmark. Valid range is 0 to 9.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();

        Example:

        Shows how adding bookmarks outlines with whitespaces(pdf, xps)
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add bookmarks with whitespaces. MS Word formats (like doc, docx) does not support bookmarks with whitespaces by default
        // and all whitespaces in the bookmarks were replaced with underscores. If you need to use bookmarks in PDF or XPS outlines, you can use them with whitespaces.
        builder.startBookmark("My Bookmark");
        builder.writeln("Text inside a bookmark.");
        
        builder.startBookmark("Nested Bookmark");
        builder.writeln("Text inside a NestedBookmark.");
        builder.endBookmark("Nested Bookmark");
        
        builder.writeln("Text after Nested Bookmark.");
        builder.endBookmark("My Bookmark");
        
        // Specify bookmarks outline level. If you are using xps format, just use XpsSaveOptions.
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("My Bookmark", 1);
        pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Nested Bookmark", 2);
        
        doc.save(getArtifactsDir() + "Bookmarks.WhiteSpaces.pdf", pdfSaveOptions);
      • clear

        public void clear()
        Removes all elements from the collection.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
      • contains

        public boolean contains(java.lang.String name)
        Determines whether the collection contains a bookmark with the given name.
        Parameters:
        name - Case-insensitive name of the bookmark to locate.
        Returns:
        True if item is found in the collection; otherwise, false.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
      • indexOfKey

        public int indexOfKey(java.lang.String name)
        Returns the zero-based index of the specified bookmark in the collection.
        Parameters:
        name - The case-insensitive name of the bookmark.
        Returns:
        The zero based index. Negative value if not found.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
      • iterator

        public java.util.Iterator<java.util.Map.Entry<java.lang.String, int>> iterator()
      • remove

        public void remove(java.lang.String name)
        Removes a bookmark with the specified name from the collection.
        Parameters:
        name - The case-insensitive name of the bookmark.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();
      • removeAt

        public void removeAt(int index)
        Removes a bookmark at the specified index.
        Parameters:
        index - The zero based index.

        Example:

        Shows how to set outline levels for bookmarks.
        // Open a blank document, create a DocumentBuilder, and use the builder to add some text wrapped inside bookmarks
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Note that whitespaces in bookmark names will be converted into underscores when saved to Microsoft Word formats
        // such as .doc and .docx, but will be preserved in other formats like .pdf or .xps
        builder.startBookmark("Bookmark 1");
        builder.writeln("Text inside Bookmark 1.");
        
        builder.startBookmark("Bookmark 2");
        builder.writeln("Text inside Bookmark 1 and 2.");
        builder.endBookmark("Bookmark 2");
        
        builder.writeln("Text inside Bookmark 1.");
        builder.endBookmark("Bookmark 1");
        
        builder.startBookmark("Bookmark 3");
        builder.writeln("Text inside Bookmark 3.");
        builder.endBookmark("Bookmark 3");
        
        // We can specify outline levels for our bookmarks so that they show up in the table of contents and are indented by an amount
        // of space proportional to the indent level in a SaveOptions object
        // Some pdf/xps readers such as Google Chrome also allow the collapsing of all higher level bookmarks by adjacent lower level bookmarks
        // This feature applies to .pdf or .xps file formats, so only their respective SaveOptions subclasses will support it
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels();
        
        outlineLevels.add("Bookmark 1", 1);
        outlineLevels.add("Bookmark 2", 2);
        outlineLevels.add("Bookmark 3", 3);
        
        Assert.assertEquals(outlineLevels.getCount(), 3);
        Assert.assertTrue(outlineLevels.contains("Bookmark 1"));
        Assert.assertEquals(outlineLevels.get(0), 1);
        Assert.assertEquals(outlineLevels.get("Bookmark 2"), 2);
        Assert.assertEquals(outlineLevels.indexOfKey("Bookmark 3"), 2);
        
        // We can remove two elements so that only the outline level designation for "Bookmark 1" is left
        outlineLevels.removeAt(2);
        outlineLevels.remove("Bookmark 2");
        
        // We have 9 bookmark levels to work with, and bookmark levels are also sorted in ascending order,
        // and get numbered in succession along that order
        // Practically this means that our three levels "1, 5, 9", will be seen as "1, 2, 3" in the output
        outlineLevels.add("Bookmark 2", 5);
        outlineLevels.add("Bookmark 3", 9);
        
        // Save the document as a .pdf and find links to the bookmarks and their outline levels
        doc.save(getArtifactsDir() + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);
        
        // We can empty this dictionary to remove the contents table
        outlineLevels.clear();