You can get the bookmark or whole document content from the JavaScript Document Editor component as plain text and SFDT (rich text).
You can selectBookmark
API to navigate to the bookmark and use text
API to get the bookmark content as plain text from JavaScript Document Editor component.
The following example code illustrates how to get the bookmark content as plain text.
import { DocumentEditorContainer, Toolbar } from '@syncfusion/ej2-documenteditor';
DocumentEditorContainer.Inject(Toolbar);
let container: DocumentEditorContainer = new DocumentEditorContainer({ enableToolbar: true, height: '590px' });
container.serviceUrl = 'https://ej2services.syncfusion.com/production/web-services/api/documenteditor/';
container.appendTo('#container');
// To insert text in cursor position
container.documentEditor.editor.insertText('Document editor');
// To select all the content in document
container.documentEditor.selection.selectAll();
// Insert bookmark to selected content
container.documentEditor.editor.insertBookmark('Bookmark1');
// Provide your bookmark name to navigate to specific bookmark
container.documentEditor.selection.selectBookmark('Bookmark1');
// To get the selected content as text
let selectedContent: string = container.documentEditor.selection.text;
To get the bookmark content as SFDT (rich text), please check this link
You can use text
API to get the whole document content as plain text from JavaScript Document Editor component.
The following example code illustrates how to get the whole document content as plain text.
import { DocumentEditorContainer, Toolbar } from '@syncfusion/ej2-documenteditor';
DocumentEditorContainer.Inject(Toolbar);
let container: DocumentEditorContainer = new DocumentEditorContainer({ enableToolbar: true, height: '590px' });
container.serviceUrl = 'https://ej2services.syncfusion.com/production/web-services/api/documenteditor/';
container.appendTo('#container');
// To insert text in cursor position
container.documentEditor.editor.insertText('Document editor');
// To select all the content in document
container.documentEditor.selection.selectAll();
// To get the content as text
let selectedContent: string = container.documentEditor.selection.text;
You can use serialize
API to get the whole document content as SFDT string from JavaScript Document Editor component.
The following example code illustrates how to get the whole document content as SFDT.
import { DocumentEditorContainer, Toolbar } from '@syncfusion/ej2-documenteditor';
DocumentEditorContainer.Inject(Toolbar);
let container: DocumentEditorContainer = new DocumentEditorContainer({ enableToolbar: true, height: '590px' });
container.serviceUrl = 'https://ej2services.syncfusion.com/production/web-services/api/documenteditor/';
container.appendTo('#container');
// To insert text in cursor position
container.documentEditor.editor.insertText('Document editor');
// To get the content as SFDT
let selectedContent: string = container.documentEditor.serialize();
You can use goToHeader
API to navigate the selection to the header and then use text
API to get the content as plain text.
The following example code illustrates how to get the header content as plain text.
import { DocumentEditorContainer, Toolbar } from '@syncfusion/ej2-documenteditor';
DocumentEditorContainer.Inject(Toolbar);
let container: DocumentEditorContainer = new DocumentEditorContainer({ enableToolbar: true, height: '590px' });
container.serviceUrl = 'https://ej2services.syncfusion.com/production/web-services/api/documenteditor/';
container.appendTo('#container');
// To navigate the selection to header
container.documentEditor.selection.goToHeader();
// To insert text in cursor position
container.documentEditor.editor.insertText('Document editor');
// To select all the content in document
container.documentEditor.selection.selectAll();
// To get the selected content as text
let selectedContent: string = container.documentEditor.selection.text;
Similarly, you can use goToFooter
API to navigate the selection to the footer and then use text
API to get the content as plain text.