Back to Devexpress

RichEditDocumentBase Class

aspnetcore-js-devexpress-dot-richedit-eba4eb98.md

latest23.2 KB
Original Source

RichEditDocumentBase Class

Defines a document in the Rich Text Editor.

Declaration

ts
export class RichEditDocumentBase

Inheritance

RichEditDocumentBase RichEditDocument

Properties

bookmarks Property

Provide access to the document’s collection of bookmarks.

Declaration

ts
get bookmarks(): BookmarkCollection<Bookmark>

Property Value

TypeDescription
BookmarkCollection<Bookmark>

A collection of bookmarks.

|

fields Property

Provides access to the document’s collection of fields.

Declaration

ts
get fields(): FieldCollection

Property Value

TypeDescription
FieldCollection

A collection of fields.

|

Remarks

javascript
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

ts
get fonts(): FontCollection

Property Value

TypeDescription
FontCollection

A collection of fonts.

|

Remarks

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

javascript
//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.

Declaration

ts
get hyperlinks(): HyperlinkCollection

Property Value

TypeDescription
HyperlinkCollection

A collection of hyperlinks.

|

Remarks

javascript
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

ts
get interval(): Interval

Property Value

TypeDescription
Interval

The text buffer interval.

|

isProtected Property

Indicates whether the document is protected.

Declaration

ts
get isProtected(): boolean

Property Value

TypeDescription
boolean

true if the document is protected; otherwise, false.

|

Remarks

js
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

ts
get length(): number

Property Value

TypeDescription
number

The number of character positions in the sub-document.

|

Remarks

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

See Also

Examples

lists Property

Provide access to the document’s collection of lists.

Declaration

ts
get lists(): ListCollection

Property Value

TypeDescription
ListCollection

A collection of lists.

|

paragraphs Property

Provide access to the document’s collection of paragraphs.

Declaration

ts
get paragraphs(): ParagraphCollection

Property Value

TypeDescription
ParagraphCollection

A collection of paragraphs.

|

rangePermissions Property

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

Declaration

ts
get rangePermissions(): RangePermissionCollection

Property Value

TypeDescription
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

ts
get sections(): SectionCollection

Property Value

TypeDescription
SectionCollection

A collection of sections.

|

Remarks

javascript
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

Examples

subDocuments Property

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

Declaration

ts
get subDocuments(): SubDocumentCollection<SubDocument>

Property Value

TypeDescription
SubDocumentCollection<SubDocument>

A collection of sub-documents.

|

See Also

Document Model

tables Property

Provide access to the document’s collection of tables.

Declaration

ts
get tables(): TableCollection

Property Value

TypeDescription
TableCollection

A collection of tables.

|

Remarks

javascript
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

ts
checkProtectionPassword(
    password: string
): boolean

Parameters

NameTypeDescription
passwordstring

The password to check.

|

Returns

TypeDescription
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.

js
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

ts
deleteText(
    interval: IInterval
): void

Parameters

NameTypeDescription
intervalIInterval

The text interval to delete.

|

Remarks

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

getCharacterProperties(interval) Method

Returns character properties of the specified text interval.

Declaration

ts
getCharacterProperties(
    interval: IInterval
): CharacterProperties

Parameters

NameTypeDescription
intervalIInterval

An object that contains information about a text interval.

|

Returns

TypeDescription
CharacterProperties

An object that contains the character properties.

|

getDefaultCharacterProperties Method

Gets the document’s default character properties.

Declaration

ts
getDefaultCharacterProperties(): CharacterProperties

Returns

TypeDescription
CharacterProperties

An object that contains the character properties.

|

Remarks

javascript
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

ts
getParagraphProperties(
    interval: IInterval
): ParagraphProperties

Parameters

NameTypeDescription
intervalIInterval

An object that contains information about a text interval.

|

Returns

TypeDescription
ParagraphProperties

An object that contains the paragraph properties.

|

getText Method

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

Declaration

ts
getText(
    interval?: Interval
): string

Parameters

NameTypeDescription
intervalInterval

A document interval.

|

Returns

TypeDescription
string

The text contained in the specified interval.

|

Remarks

javascript
var mainSubDocumentText = richEdit.document.getText();

See Also

Examples

insertColumnBreak(position) Method

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

Declaration

ts
insertColumnBreak(
    position: number
): Interval

Parameters

NameTypeDescription
positionnumber

The position in the main sub-document.

|

Returns

TypeDescription
Interval

The interval that contains the inserted column break.

|

insertLineBreak(position) Method

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

Declaration

ts
insertLineBreak(
    position: number
): Interval

Parameters

NameTypeDescription
positionnumber

A position in the document.

|

Returns

TypeDescription
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

ts
insertPageBreak(
    position: number
): Interval

Parameters

NameTypeDescription
positionnumber

The position in the main sub-document.

|

Returns

TypeDescription
Interval

The interval that contains the inserted page break.

|

insertParagraph(position) Method

Inserts a paragraph mark to the specified position.

Declaration

ts
insertParagraph(
    position: number
): Paragraph

Parameters

NameTypeDescription
positionnumber

The position in the document.

|

Returns

TypeDescription
Paragraph

The newly created paragraph.

|

Remarks

javascript
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

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

Parameters

NameTypeDescription
positionnumber

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

javascript
var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var image = "your-image-URL"; // 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

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

Parameters

NameTypeDescription
positionnumber

A position in the document.

| | type | SectionBreakType |

The type of a section break.

|

Returns

TypeDescription
Section

The newly created section

|

insertText(position, text) Method

Inserts the specified text at the specified position.

Declaration

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

Parameters

NameTypeDescription
positionnumber

A position to insert the text.

| | text | string |

The text to insert.

|

Returns

TypeDescription
Interval

The interval that contains the inserted text.

|

Remarks

javascript
var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
subDocument.insertText(position, 'text');
javascript
var subDocument = richEdit.selection.activeSubDocument;
var position = subDocument.length - 1;
subDocument.insertText(position, 'text');
javascript
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

ts
protect(
    password: string
): void

Parameters

NameTypeDescription
passwordstring

The password.

|

Remarks

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

js
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

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

Parameters

NameTypeDescription
intervalIInterval

An object that contains information about a text interval.

| | characterProperties | ICharacterProperties |

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

|

Remarks

javascript
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

ts
setDefaultCharacterProperties(
    characterProperties: ICharacterProperties
): void

Parameters

NameTypeDescription
characterPropertiesICharacterProperties

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

|

Remarks

javascript
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

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

Parameters

NameTypeDescription
intervalIInterval

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

ts
unprotect(): void

Remarks

js
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