RichEditDocumentBase Class

Defines a document in the Rich Text Editor.

Declaration

export class RichEditDocumentBase

Inheritance

RichEditDocumentBase

Properties

bookmarks Property

Provide access to the document's collection of bookmarks.

Declaration

readonly bookmarks: BookmarkCollection<Bookmark>

Property Value

Type Description
BookmarkCollection<Bookmark>

A collection of bookmarks.

fields Property

Provides access to the document's collection of fields.

Declaration

readonly fields: FieldCollection

Property Value

Type Description
FieldCollection

A collection of fields.

Remarks

var doInAllSubDocuments = true;
var updateTocFields = true;
var options = new DevExpress.RichEdit.UpdateFieldsOptions(doInAllSubDocuments, updateTocFields);
richEdit.document.fields.updateAllFields(function() {
    console.log('Updated');
}, options);

fonts Property

Provide access to the document's collection of fonts.

Declaration

readonly fonts: FontCollection

Property Value

Type Description
FontCollection

A collection of fonts.

Remarks

Use this property to access the fonts available in the document.

//reduces the document's font collection to the specified fonts
var myFonts = ['Arial', 'Calibri'];
richEdit.document.fonts.getAllFontNames().forEach(fontName => 
    myFonts.find(myFontName => 
        myFontName == fontName) ? null : richEdit.document.fonts.getByName(fontName).delete());

Provides access to the document's collection of hyperlinks.

readonly hyperlinks: HyperlinkCollection
Type Description
HyperlinkCollection

A collection of hyperlinks.

var text = "Visit our site";
var url = "https://www.devexpress.com/";
var tooltip = "DevExpress site";

richEdit.beginUpdate();
richEdit.history.beginTransaction();
var subDocument = richEdit.selection.activeSubDocument;

var position = richEdit.selection.active;
position = subDocument.insertParagraph(position).interval.end;
position = subDocument.hyperlinks.create(position, new DevExpress.RichEdit.HyperlinkInfo(text, url, "", tooltip)).interval.end;
subDocument.insertParagraph(position);

richEdit.endUpdate();
richEdit.history.endTransaction();

interval Property

Gets the text buffer interval that contains the document.

Declaration

readonly interval: Interval

Property Value

Type Description
Interval

The text buffer interval.

isProtected Property

Indicates whether the document is protected.

Declaration

readonly isProtected: boolean

Property Value

Type Description
boolean

true, if the document is protected; otherwise, false.

Remarks

function ProtectDocument() {
   if (!richEdit.document.isProtected) {
       const password = window.prompt('enter new password(optional):', '');
   if (password != undefined && password != null)
       richEdit.document.protect(password);
   }
}

function UnprotectDocument() {
   const password = window.prompt('enter password:', '');
   if (password != undefined && password != null) {
       if (richEdit.document.checkProtectionPassword(password))
           richEdit.document.unprotect();
       else
           window.alert('The password incorrect!');
   }
}

Refer to the following help topic for more information: Document Protection.

Run Demo: Document Protection

length Property

Gets the character length of the document.

Declaration

readonly length: number

Property Value

Type Description
number

The number of character positions in the sub-document.

Remarks

var subDocument = richEdit.document.subDocuments.main;
subDocument.insertText(subDocument.length - 1, 'text'); 
// or
richEdit.document.insertText(richEdit.document.length - 1, 'text');
See Also

lists Property

Provide access to the document's collection of lists.

Declaration

readonly lists: ListCollection

Property Value

Type Description
ListCollection

A collection of lists.

paragraphs Property

Provide access to the document's collection of paragraphs.

Declaration

readonly paragraphs: ParagraphCollection

Property Value

Type Description
ParagraphCollection

A collection of paragraphs.

rangePermissions Property

Provides access to the document's collection of range permissions.

Declaration

readonly rangePermissions: RangePermissionCollection

Property Value

Type Description
RangePermissionCollection

A collection of range permissions.

Remarks

Refer to the following help topic for more information: Document Protection.

sections Property

Provide access to the document's collection of sections.

Declaration

readonly sections: SectionCollection

Property Value

Type Description
SectionCollection

A collection of sections.

Remarks

var createHeaderIfNotExist = true;
var section = richEdit.document.sections.getByIndex(0);
var subDocument = section.getHeader(DevExpress.RichEdit.HeaderFooterType.Primary, createHeaderIfNotExist);
var position = 0;
subDocument.insertText(position, 'text');
See Also

subDocuments Property

Provide access to the document's collection of sub-documents.

Declaration

readonly subDocuments: SubDocumentCollection<SubDocument>

Property Value

Type Description
SubDocumentCollection<SubDocument>

A collection of sub-documents.

See Also

tables Property

Provide access to the document's collection of tables.

Declaration

readonly tables: TableCollection

Property Value

Type Description
TableCollection

A collection of tables.

Remarks

var columnCount = 5;
var rowCount = 5;
var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var table = subDocument.tables.create(position, columnCount, rowCount);

Methods

checkProtectionPassword(password) Method

Checks whether the specified password was used to protect the document.

Declaration

checkProtectionPassword(
    password: string
): boolean

Parameters

Name Type Description
password string

The password to check.

Returns

Type Description
boolean

true, if the document is protected with the specified password; otherwise, false.

Remarks

The protect(password) method allows you to protect a document with a password. To check whether a password was used to protect the document, use the checkProtectionPassword method.

function ProtectDocument() {
   if (!richEdit.document.isProtected) {
       const password = window.prompt('enter new password(optional):', '');
   if (password != undefined && password != null)
       richEdit.document.protect(password);
   }
}

function UnprotectDocument() {
   const password = window.prompt('enter password:', '');
   if (password != undefined && password != null) {
       if (richEdit.document.checkProtectionPassword(password))
           richEdit.document.unprotect();
       else
           window.alert('The password incorrect!');
   }
}

Refer to the following help topic for more information: Document Protection.

Run Demo: Document Protection

deleteText(interval) Method

Deletes the specified text interval.

Declaration

deleteText(
    interval: IInterval
): void

Parameters

Name Type Description
interval IInterval

The text interval to delete.

Remarks

richEdit.document.deleteText(new DevExpress.RichEdit.Interval(0, 5));

getCharacterProperties(interval) Method

Returns character properties of the specified text interval.

Declaration

getCharacterProperties(
    interval: IInterval
): CharacterProperties

Parameters

Name Type Description
interval IInterval

An object that contains information about a text interval.

Returns

Type Description
CharacterProperties

An object that contains the character properties.

getDefaultCharacterProperties Method

Gets the document's default character properties.

Declaration

getDefaultCharacterProperties(): CharacterProperties

Returns

Type Description
CharacterProperties

An object that contains the character properties.

Remarks

const charProps = richEdit.document.getDefaultCharacterProperties();
charProps.fontName = "Segoe UI";
richEdit.document.setDefaultCharacterProperties(charProps);

getParagraphProperties(interval) Method

Returns paragraph properties of the specified text interval.

Declaration

getParagraphProperties(
    interval: IInterval
): ParagraphProperties

Parameters

Name Type Description
interval IInterval

An object that contains information about a text interval.

Returns

Type Description
ParagraphProperties

An object that contains the paragraph properties.

getText Method

Return the document's textual representation contained in the specified interval.

Declaration

getText(
    interval?: Interval
): string

Parameters

Name Type Description
interval Interval

A document interval.

Returns

Type Description
string

The text contained in the specified interval.

Remarks

var mainSubDocumentText = richEdit.document.getText();
See Also

insertColumnBreak(position) Method

Inserts the column break at the specified position in the main sub-document.

Declaration

insertColumnBreak(
    position: number
): Interval

Parameters

Name Type Description
position number

The position in the main sub-document.

Returns

Type Description
Interval

The interval that contains the inserted column break.

insertLineBreak(position) Method

Inserts the line break at the specified position in the document.

Declaration

insertLineBreak(
    position: number
): Interval

Parameters

Name Type Description
position number

A position in the document.

Returns

Type Description
Interval

The interval that contains the inserted line break.

insertPageBreak(position) Method

Inserts the page break at the specified position in the main sub-document.

Declaration

insertPageBreak(
    position: number
): Interval

Parameters

Name Type Description
position number

The position in the main sub-document.

Returns

Type Description
Interval

The interval that contains the inserted page break.

insertParagraph(position) Method

Inserts a paragraph mark to the specified position.

Declaration

insertParagraph(
    position: number
): Paragraph

Parameters

Name Type Description
position number

The position in the document.

Returns

Type Description
Paragraph

The newly created paragraph.

Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var templateText = '[Type your text here]';

richEdit.beginUpdate();
richEdit.history.beginTransaction();

position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertText(position, 'Dear Mr Stanley,').end;
position = subDocument.insertParagraph(position).interval.end;
var tmpTextInterval = subDocument.insertText(position, templateText);
position = tmpTextInterval.end;
position = subDocument.insertParagraph(position).interval.end;

richEdit.endUpdate();
richEdit.history.endTransaction();

richEdit.selection.setSelection(tmpTextInterval);
richEdit.focus();

insertPicture(position, base64) Method

Inserts a picture to the document.

Declaration

insertPicture(
    position: number,
    base64: string,
    size?: Size,
    callback?: (interval: Interval) => void
): void

Parameters

Name Type Description
position number

A position in the document.

base64 string

The picture in string representation that is encoded with base-64 digits.

size Size

The image size.

callback (interval: Interval) => void

A function that is called after the picture is inserted.

Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var image = ""; // base64 or url
var width = richEdit.unitConverter.pixelsToTwips(100);
var height = richEdit.unitConverter.pixelsToTwips(100);
var size = new DevExpress.RichEdit.Size(width, height);
subDocument.insertPicture(position, image, size, function(interval) { console.log("Picture loaded"); });

insertSectionBreak(position, type) Method

Inserts the section break at the specified position in the document.

Declaration

insertSectionBreak(
    position: number,
    type: SectionBreakType
): Section

Parameters

Name Type Description
position number

A position in the document.

type SectionBreakType

The type of a section break.

Returns

Type Description
Section

The newly created section

insertText(position, text) Method

Inserts the specified text at the specified position.

Declaration

insertText(
    position: number,
    text: string
): Interval

Parameters

Name Type Description
position number

A position to insert the text.

text string

The text to insert.

Returns

Type Description
Interval

The interval that contains the inserted text.

Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
subDocument.insertText(position, 'text');
var subDocument = richEdit.selection.activeSubDocument;
var position = subDocument.length - 1;
subDocument.insertText(position, 'text'); 
var createHeaderIfNotExist = true;
var section = richEdit.document.sections.getByIndex(0);
var subDocument = section.getHeader(DevExpress.RichEdit.HeaderFooterType.Primary, createHeaderIfNotExist);
var position = 0;
subDocument.insertText(position, 'text');

protect(password) Method

Protects the document with the specified password.

Declaration

protect(
    password: string
): void

Parameters

Name Type Description
password string

The password.

Remarks

Use the checkProtectionPassword(password) and unprotect methods to authenticate the password and unprotect the document.

function ProtectDocument() {
   if (!richEdit.document.isProtected) {
       const password = window.prompt('enter new password(optional):', '');
   if (password != undefined && password != null)
       richEdit.document.protect(password);
   }
}

function UnprotectDocument() {
   const password = window.prompt('enter password:', '');
   if (password != undefined && password != null) {
       if (richEdit.document.checkProtectionPassword(password))
           richEdit.document.unprotect();
       else
           window.alert('The password incorrect!');
   }
}

Refer to the following help topic for more information: Document Protection.

Run Demo: Document Protection

setCharacterProperties(interval, characterProperties) Method

Applies character properties to a text interval.

Declaration

setCharacterProperties(
    interval: IInterval,
    characterProperties: ICharacterProperties
): void

Parameters

Name Type Description
interval IInterval

An object that contains information about a text interval.

characterProperties ICharacterProperties

A CharacterProperties object that implements the ICharacterProperties interface and contains character properties.

Remarks

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var characterProperties = {
    bold: true,
    fontName: richEdit.document.fonts.getByIndex(0).name,
    highlightColor: "ffff00",
};

richEdit.history.beginTransaction();
richEdit.beginUpdate();
var interval = subDocument.insertText(position, "text");
subDocument.setCharacterProperties(interval, characterProperties);
richEdit.endUpdate();
richEdit.history.endTransaction();

setDefaultCharacterProperties(characterProperties) Method

Sets the document's default character properties.

Declaration

setDefaultCharacterProperties(
    characterProperties: ICharacterProperties
): void

Parameters

Name Type Description
characterProperties ICharacterProperties

A CharacterProperties object that implements the ICharacterProperties interface and contains character properties.

Remarks

const charProps = richEdit.document.getDefaultCharacterProperties();
charProps.fontName = "Segoe UI";
richEdit.document.setDefaultCharacterProperties(charProps);

setParagraphProperties(interval, paragraphProperties) Method

Applies paragraph properties to a text interval.

Declaration

setParagraphProperties(
    interval: IInterval,
    paragraphProperties: IParagraphProperties
): void

Parameters

Name Type Description
interval IInterval

An object that contains information about a text interval.

paragraphProperties IParagraphProperties

A ParagraphProperties object that implements the IParagraphProperties interface and contains paragraph properties.

unprotect Method

Unprotects the document.

Declaration

unprotect(): void

Remarks

function ProtectDocument() {
   if (!richEdit.document.isProtected) {
       const password = window.prompt('enter new password(optional):', '');
   if (password != undefined && password != null)
       richEdit.document.protect(password);
   }
}

function UnprotectDocument() {
   const password = window.prompt('enter password:', '');
   if (password != undefined && password != null) {
       if (richEdit.document.checkProtectionPassword(password))
           richEdit.document.unprotect();
       else
           window.alert('The password incorrect!');
   }
}

Refer to the following help topic for more information: Document Protection.

Run Demo: Document Protection