Work with Bookmarks

Contents
[ ]

Use the StartBookmark and EndBookmark to create a bookmark by marking its start and end, respectively. Do not forget to pass the same bookmark name to both methods.

Bookmarks in a document can overlap and span any range. Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.

The following code example shows how to set and get bookmarks:

Document doc = new Document("../../data/document.doc");
DocumentBuilder builder = new DocumentBuilder(doc);

// ----- Set Bookmark
builder.StartBookmark("AsposeBookmark");
builder.Writeln("Text inside a bookmark.");
builder.EndBookmark("AsposeBookmark");

// ----- Get Bookmark

// By index.
Bookmark bookmark1 = doc.Range.Bookmarks[0];

// By name.
Bookmark bookmark2 = doc.Range.Bookmarks["AsposeBookmark"];
doc.Save("AsposeBookmarks.doc");

See also: