Search results

Bookmarks in React DocumentEditor component

29 Nov 2022 / 2 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.

Copied to clipboard
this.container.documentEditor.editor.insertBookmark("Bookmark1");

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.

Copied to clipboard
this.container.documentEditor.selection.selectBookmark("Bookmark1");

Delete Bookmark

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

Copied to clipboard
this.container.documentEditor.editor.deleteBookmark("Bookmark1");

Get Bookmark

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

Copied to clipboard
this.container.documentEditor.selection.getBookmarks(false);

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

Bookmark Dialog

The following example shows how to open bookmark dialog in document editor.

Copied to clipboard
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { DocumentEditorComponent, SfdtExport, Selection, Editor, BookmarkDialog } from '@syncfusion/ej2-react-documenteditor';

DocumentEditorComponent.Inject(SfdtExport, Selection, Editor, BookmarkDialog);
export class Default extends React.Component<{}, {}> {
    public documenteditor: DocumentEditorComponent;
    showBookmarkDialog(): void {
        //Open bookmark dialog.
        this.documenteditor.showDialog('Bookmark');
    }
    render() {
        return (
            <div>
                <button onClick={this.showBookmarkDialog.bind(this)}>Dialog</button>
                <DocumentEditorComponent id="container" height={'330px'} ref={(scope) => { this.documenteditor = scope; }} isReadOnly={false} enableSelection={true} enableEditor={true} enableSfdtExport={true} enableBookmarkDialog={true} />
            </div>
        );
    }
}
ReactDOM.render(<Default />, document.getElementById('sample'));
Copied to clipboard
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { DocumentEditorComponent, SfdtExport, Selection, Editor, BookmarkDialog } from '@syncfusion/ej2-react-documenteditor';
DocumentEditorComponent.Inject(SfdtExport, Selection, Editor, BookmarkDialog);
export class Default extends React.Component {
    showBookmarkDialog() {
        //Open bookmark dialog.
        this.documenteditor.showDialog('Bookmark');
    }
    render() {
        return (<div>
                <button onClick={this.showBookmarkDialog.bind(this)}>Dialog</button>
                <DocumentEditorComponent id="container" height={'330px'} ref={(scope) => { this.documenteditor = scope; }} isReadOnly={false} enableSelection={true} enableEditor={true} enableSfdtExport={true} enableBookmarkDialog={true}/>
            </div>);
    }
}
ReactDOM.render(<Default />, document.getElementById('sample'));

See Also