Click or drag to resize
Bookmark Class
Represents the bookmark (pair of BookmarkStart and BookmarkEnd elements).
Inheritance Hierarchy
SystemObject
  GemBox.DocumentBookmark

Namespace:  GemBox.Document
Assembly:  GemBox.Document (in GemBox.Document.dll) Version: 25.3.30.1255
Syntax
public sealed class Bookmark

The Bookmark type exposes the following members.

Properties
  NameDescription
Public propertyEnd
Gets the BookmarkEnd element.
Public propertyName
Gets the bookmark name.
Public propertyStart
Gets the BookmarkStart element.
Top
Methods
  NameDescription
Public methodGetContent
Gets the content of the current Bookmark.
Top
Remarks

A Bookmark object serves as a façade for BookmarkStart and BookmarkEnd elements.

Bookmark objects can be retrieved from DocumentModel.Bookmarks collection. DocumentModel.Bookmarks collection contains all bookmarks in the document. Use DocumentModel.Bookmarks collection to retrieve a Bookmark with a specified name, iterate over all bookmarks or remove a bookmark.

Bookmarks are usually used in a conjunction with Hyperlinks or Fields for navigating to a bookmarked part of the document or to render a page number (or some other information) of a bookmarked part of the document. For more information, see Bookmarks and Hyperlinks and Modify Bookmarks samples.

Examples

Following example shows how to insert a bookmarked content to a document, and later retrieve and delete it through DocumentModel.Bookmarks collection.

// Create a new empty document.
var doc = new DocumentModel();

// Insert a bookmarked text.
doc.Sections.Add(
    new Section(doc, 
        new Paragraph(doc, 
            new BookmarkStart(doc, "MyBookmark"), 
            new Run(doc, "My bookmarked text"), 
            new BookmarkEnd(doc, "MyBookmark"))));


// Retrieve a bookmark.
var myBookmark = doc.Bookmarks["MyBookmark"];

// Delete a bookmark. Deletes BookmarkStart and BookmarkEnd elements. Content that was bookmarked will not be deleted!
doc.Bookmarks.Remove(myBookmark);
See Also