BookmarksOutlineLevelCollection Class

A collection of individual bookmarks outline level.
Inheritance Hierarchy
SystemObject
  Aspose.Words.SavingBookmarksOutlineLevelCollection

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class BookmarksOutlineLevelCollection : IEnumerable<KeyValuePair<string, int>>, 
	IEnumerable

The BookmarksOutlineLevelCollection type exposes the following members.

Constructors
  NameDescription
Public methodBookmarksOutlineLevelCollection
Initializes a new instance of the BookmarksOutlineLevelCollection class
Properties
  NameDescription
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.
Methods
  NameDescription
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 (Inherited from Object.)
Public methodGetEnumerator
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (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 (Inherited from Object.)
Remarks

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.

Examples
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.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.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(ArtifactsDir + "BookmarksOutlineLevelCollection.BookmarkLevels.pdf", pdfSaveOptions);

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