Bookmarks are used frequently to mark particular places in the document where new elements are to be inserted. To move to a bookmark, use MoveToBookmark. This method has two overloads. The simplest one accepts nothing but the name of the bookmark where the cursor is to be moved.
Example DocumentBuilderMoveToBookmark
Shows how to move a cursor position to a bookmark.
[C#]
Document doc = new Document(MyDir + "DocumentBuilder.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("CoolBookmark");
builder.Writeln("This is a very cool bookmark.");
[Visual Basic]
Dim doc As Document = New Document(MyDir & "DocumentBuilder.doc")
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.MoveToBookmark("CoolBookmark")
builder.Writeln("This is a very cool bookmark.")
[Java]
Document doc = new Document(getMyDir() + "DocumentBuilder.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToBookmark("CoolBookmark");
builder.writeln("This is a very cool bookmark.");
This overload moves the cursor to a position just after the start of the bookmark with the specified name.
Another overload moves the cursor to a bookmark with greater precision. It accepts two additional boolean parameters:
- isStart determines whether to move the cursor to the beginning or to the end of the bookmark.
- isAfter determines whether to move the cursor to be after the bookmark start or end position, or to move the cursor to be before the bookmark start or end position.
Example DocumentBuilderMoveToBookmarkEnd
Shows how to move a cursor position to just after the bookmark end.
[C#]
Document doc = new Document(MyDir + "DocumentBuilder.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("CoolBookmark", false, true);
builder.Writeln("This is a very cool bookmark.");
[Visual Basic]
Dim doc As Document = New Document(MyDir & "DocumentBuilder.doc")
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.MoveToBookmark("CoolBookmark", False, True)
builder.Writeln("This is a very cool bookmark.")
[Java]
Document doc = new Document(getMyDir() + "DocumentBuilder.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToBookmark("CoolBookmark", false, true);
builder.writeln("This is a very cool bookmark.");
The comparison for both methods is not case-sensitive.
Inserting new text in this way does not replace the existing text of the bookmark.
Note that some bookmarks in the document are assigned to form fields. Moving to such a bookmark and inserting text there inserts the text into the form field code. Although this will not invalidate the form field, the inserted text will not be visible because it becomes part of the field code.