end_bookmark method
end_bookmark(bookmark_name)
Marks the current position in the document as a bookmark end.
def end_bookmark(self, bookmark_name: str):
...
Parameter | Type | Description |
---|---|---|
bookmark_name | str | Name of the bookmark. |
Remarks
Bookmarks in a document can overlap and span any range. To create a valid bookmark you need to call both DocumentBuilder.start_bookmark() and DocumentBuilder.end_bookmark() with the same bookmarkName parameter.
Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.
Returns
The bookmark end node that was just created.
Examples
Shows how create a bookmark.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# A valid bookmark needs to have document body text enclosed by
# BookmarkStart and BookmarkEnd nodes created with a matching bookmark name.
builder.start_bookmark('MyBookmark')
builder.writeln('Hello world!')
builder.end_bookmark('MyBookmark')
self.assertEqual(1, doc.range.bookmarks.count)
self.assertEqual('MyBookmark', doc.range.bookmarks[0].name)
self.assertEqual('Hello world!', doc.range.bookmarks[0].text.strip())
Shows how to insert a hyperlink which references a local bookmark.
doc = aw.Document()
builder = aw.DocumentBuilder(doc)
builder.start_bookmark('Bookmark1')
builder.write('Bookmarked text. ')
builder.end_bookmark('Bookmark1')
builder.writeln('Text outside of the bookmark.')
# Insert a HYPERLINK field that links to the bookmark. We can pass field switches
# to the "insert_hyperlink" method as part of the argument containing the referenced bookmark's name.
builder.font.color = aspose.pydrawing.Color.blue
builder.font.underline = aw.Underline.SINGLE
hyper_link = builder.insert_hyperlink('Link to Bookmark1', 'Bookmark1', True).as_field_hyperlink()
hyper_link.screen_tip = 'Hyperlink Tip'
doc.save(ARTIFACTS_DIR + 'DocumentBuilder.insert_hyperlink_to_local_bookmark.docx')
See Also
- module aspose.words
- class DocumentBuilder