Bookmark in Vue Document editor component

30 Mar 20235 minutes to read

Bookmark is a powerful tool that helps you to mark a place in the document to find again easily. You can enter many bookmarks in the document and give each one a unique name to identify easily.

Document Editor provides built-in dialog to add, delete, and navigate bookmarks within the document. To add a bookmark, select a portion of text in the document. After that, jump to the location or add links to it within the document using built-in hyperlink dialog. You can also delete bookmarks from a document.

Bookmark names need to begin with a letter. They can include both numbers and letters, but not spaces. To separate the words, use an underscore.
Bookmark names starting with an underscore are called hidden bookmarks. For example, bookmarks generated for table of contents.

Add bookmark

Using insertBookmark method, Bookmark can be added to the selected text.


Select Bookmark

You can select the bookmark in the document using selectBookmark method by providing Bookmark name to select as shown in the following code snippet.

this.$refs.container.ej2Instances.documentEditor.selection.selectBookmark("Bookmark1", true)

Note: Second parameter is optional parameter and it denotes is exclude bookmark start and end from selection. If true, excludes bookmark start and end from selection.

Delete Bookmark

You can delete bookmark in the document using deleteBookmark method as shown in the following code snippet.


Get Bookmark from document

You can get all the bookmarks in the document using getBookmarks method as shown in the following code snippet.


Note: Parameter denotes is include hidden bookmarks. If false, ignore hidden bookmark.

Get Bookmark from selection

You can get bookmarks in current selection in the document using getBookmarks method as shown in the following code snippet.


Replace bookmark content

You can replace bookmark content without removing the bookmark start and end for backtracking the bookmark content.

this.$refs.container.ej2Instances.documentEditor.selection.selectBookmark("Bookmark1", true);
this.$refs.container.ej2Instances.documentEditor.editor.insertText('Hello World')

You can replace content by removing the bookmark start and end, thus the bookmark content can’t be tracked in future.

this.$refs.container.ej2Instances.documentEditor.editor.insertText('Hello World')

Show or Hide bookmark

You can show or hide the show square brackets around bookmarked items in Document editor component.

The following example code illustrates how to show or hide square brackets around bookmarked items.

this.$refs.container.ej2Instances.documentEditorSettings.showBookmarks = true;

Bookmark Dialog

The following example shows how to open bookmark dialog in Document Editor.

      <div id="app">
              <button v-on:click='showBookmarkDialog'>Open dialog</button>
          <ejs-documenteditor ref="documenteditor" :enableSelection='true' :isReadOnly='false' :enableEditor='true' :enableEditorHistory='true' :enableBookmarkDialog='true' height="370px" style="width: 100%;"></ejs-documenteditor>
      import Vue from 'vue'
      import { DocumentEditorPlugin, Selection, Editor, SfdtExport, EditorHistory, BookmarkDialog } from '@syncfusion/ej2-vue-documenteditor';


      export default {
          data: function() {
              return {
          provide: {
              //Inject require modules.
              DocumentEditor : [Selection, Editor, BookmarkDialog , EditorHistory, SfdtExport]
          methods: {
              showBookmarkDialog: function() {
                  //Open bookmark dialog.
    @import "../../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";

See Also