BookmarksOutlineLevelCollection Class

A collection of individual bookmarks outline level.

ExpandedInheritance Hierarchy


Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.5.0


public class BookmarksOutlineLevelCollection : IEnumerable, 
	IEnumerable<KeyValuePair<string, int>>

The BookmarksOutlineLevelCollection type exposes the following members.


Public methodBookmarksOutlineLevelCollection
Initializes a new instance of the BookmarksOutlineLevelCollection class


Public propertyCode exampleCount
Gets the number of elements contained in the collection.
Public propertyCode exampleItemInt32
Gets or sets a bookmark outline level at the specified index.
Public propertyCode exampleItemString
Gets or a sets a bookmark outline level by the bookmark name.


Public methodCode exampleAdd
Adds a bookmark to the collection.
Public methodCode exampleClear
Removes all elements from the collection.
Public methodCode exampleContains
Determines whether the collection contains a bookmark with the given name.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetEnumerator
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleIndexOfKey
Returns the zero-based index of the specified bookmark in the collection.
Public methodCode exampleRemove
Removes a bookmark with the specified name from the collection.
Public methodCode exampleRemoveAt
Removes a bookmark at the specified index.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)


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.


Shows how to set outline levels for bookmarks.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a bookmark with another bookmark nested inside it.
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");

// Insert another bookmark.
builder.StartBookmark("Bookmark 3");
builder.Writeln("Text inside Bookmark 3.");
builder.EndBookmark("Bookmark 3");

// When saving to .pdf, bookmarks can be accessed via a drop-down menu and used as anchors by most readers.
// Bookmarks can also have numeric values for outline levels,
// enabling lower level outline entries to hide higher-level child entries when collapsed in the reader.
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
BookmarksOutlineLevelCollection outlineLevels = pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels;

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

Assert.AreEqual(3, outlineLevels.Count);
Assert.True(outlineLevels.Contains("Bookmark 1"));
Assert.AreEqual(1, outlineLevels[0]);
Assert.AreEqual(2, outlineLevels["Bookmark 2"]);
Assert.AreEqual(2, outlineLevels.IndexOfKey("Bookmark 3"));

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

// There are nine outline levels. Their numbering will be optimized during the save operation.
// In this case, levels "5" and "9" will become "2" and "3".
outlineLevels.Add("Bookmark 2", 5);
outlineLevels.Add("Bookmark 3", 9);

doc.Save(ArtifactsDir + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);

// Emptying this collection will preserve the bookmarks and put them all on the same outline level.

ExpandedSee Also