Back to Devexpress

SubDocument Class

aspnetcore-js-devexpress-dot-richedit-7faeab68.md

latest18.6 KB
Original Source

SubDocument Class

Defines a sub-document in a document.

Declaration

ts
export class SubDocument

Inheritance

SubDocument SubDocumentBase

See Also

Document Model

Properties

bookmarks Property

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

Declaration

ts
get bookmarks(): BookmarkCollection<Bookmark>

Property Value

TypeDescription
BookmarkCollection<Bookmark>

A collection of bookmarks.

|

fields Property

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

Declaration

ts
get fields(): FieldCollection

Property Value

TypeDescription
FieldCollection

A collection of fields.

|

Remarks

javascript
var subDocument = richEdit.selection.activeSubDocument;
var field = subDocument.fields.create(richEdit.selection.active, 'time');
field.update(function(self) {
    console.log('Result: ' + subDocument.getText(self.resultInterval));
});

See Also

Common Use Cases: Field

Provides access to the sub-document’s collection of hyperlinks.

Declaration

ts
get hyperlinks(): HyperlinkCollection

Property Value

TypeDescription
HyperlinkCollection

A collection of hyperlinks.

|

id Property

Gets the sub-document identifier.

Declaration

ts
get id(): number

Property Value

TypeDescription
number

The sub-document identifier.

|

images Property

Provides access to the sub-document’s images.

Declaration

ts
get images(): Images

Property Value

TypeDescription
Images

An object that allows you to manage sub-document images.

|

See Also

How to: Create 'Change Image Size' ribbon items

interval Property

Gets the text buffer interval that contains the sub-document.

Declaration

ts
get interval(): Interval

Property Value

TypeDescription
Interval

The text buffer interval.

|

Remarks

javascript
var subDocument = richEdit.selection.activeSubDocument;
subDocument.deleteText(subDocument.interval);

See Also

Examples

length Property

Gets the character length of the sub-document.

Declaration

ts
get length(): number

Property Value

TypeDescription
number

The number of character positions in the sub-document.

|

Remarks

javascript
var subDocument = richEdit.selection.activeSubDocument;
var position = subDocument.length - 1;
subDocument.insertText(position, 'text');

See Also

Examples

paragraphs Property

Provide access to sub-document paragraphs.

Declaration

ts
get paragraphs(): ParagraphCollection

Property Value

TypeDescription
ParagraphCollection

A collection of sub-document paragraphs.

|

parentSubDocument Property

Returns a sub-document where the current sub-document is placed.

Declaration

ts
get parentSubDocument(): SubDocument | null

Property Value

TypeDescription
SubDocument

The parent sub-document. null if the current sub-document is a header or footer, or the main document.

|

Remarks

Use the parentSubDocument method to get a sub-document where the current TextBox sub-document is placed. For other sub-document types (Header, Foorer, or Main), the method returns null.

rangePermissions Property

Provides access to the sub-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.

tables Property

Provide access to sub-document tables.

Declaration

ts
get tables(): TableCollection

Property Value

TypeDescription
TableCollection

A collection of sub-document tables.

|

type Property

Gets the sub-document type.

Declaration

ts
get type(): SubDocumentType

Property Value

TypeDescription
SubDocumentType

The sub-document type.

|

Methods

deleteText(interval) Method

Deletes the specified text interval.

Declaration

ts
deleteText(
    interval: IInterval
): void

Parameters

NameTypeDescription
intervalIInterval

The text interval to delete.

|

Remarks

javascript
var subDocument = richEdit.selection.activeSubDocument;
subDocument.deleteText(subDocument.interval);

See Also

Common Use Cases: Text

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.

|

getHtml Method

Returns the content of the specified sub-document interval in HTML format (HTML).

Declaration

ts
getHtml(
    interval?: IInterval
): string

Parameters

NameTypeDescription
intervalIInterval

A text interval.

|

Returns

TypeDescription
string

The HTML text.

|

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.

|

getRtf Method

Returns the content of the specified sub-document interval in Rich Text Format (RTF).

Declaration

ts
getRtf(
    interval?: IInterval
): string

Parameters

NameTypeDescription
intervalIInterval

A text interval.

|

Returns

TypeDescription
string

The RTF text.

|

getText Method

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

Declaration

ts
getText(
    interval?: IInterval
): string

Parameters

NameTypeDescription
intervalIInterval

A document interval.

|

Returns

TypeDescription
string

The text contained in the specified interval.

|

Remarks

javascript
var selectedText = richEdit.selection.activeSubDocument.getText(richEdit.selection.intervals[0]);

See Also

Common Use Cases: Text

insertColumnBreak(position) Method

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

Declaration

ts
insertColumnBreak(
    position: number
): Interval

Parameters

NameTypeDescription
positionnumber

The position in the sub-document.

|

Returns

TypeDescription
Interval

The interval that contains the inserted column break.

|

insertContent(position, content, documentFormat) Method

Inserts the content at the specified position.

Declaration

ts
insertContent(
    position: number,
    content: string | File | Blob | ArrayBuffer,
    documentFormat: DocumentFormat,
    callback?: (interval: Interval,
    success: boolean) => void
): void

Parameters

NameTypeDescription
positionnumber

A position in the document.

| | content | string | File | Blob | ArrayBuffer |

The content to insert.

| | documentFormat | DocumentFormat |

The document format of the inserted content.

| | callback | (interval: Interval, success: boolean) => void |

A function that is called after the content is inserted. The interval parameter returns the inserted content’s interval. The success parameter specifies whether the content was successfully inserted.

|

Remarks

The code sample below exports the document content to a file and inserts it in the current position.

javascript
richEdit.exportToFile(function(file){
  richEdit.selection.activeSubDocument.insertContent(richEdit.selection.active, 
    file, DevExpress.RichEdit.DocumentFormat.OpenXml, function (interval, success){
      if (success)  
        console.log('Inserted interval [' + interval.start + ', ' + interval.end + ']');
  });
}, DevExpress.RichEdit.DocumentFormat.OpenXml);

insertHtml(position, htmlText) Method

Inserts the specified HTML text at the specified position.

Declaration

ts
insertHtml(
    position: number,
    htmlText: string,
    callback?: (interval: Interval) => void
): void

Parameters

NameTypeDescription
positionnumber

A position in the sub-document.

| | htmlText | string |

The HTML text.

| | callback | (interval: Interval) => void |

A function that is called after the HTML text is inserted.

|

Remarks

Use the insertHtml method to insert the HTML text at the specified sub-document position. After the insertion, RichEdit calls the callback function.

If the htmlText parameter contains an entire document, the RichEdit control inserts the content of the main sub-document only.

insertLineBreak(position) Method

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

Declaration

ts
insertLineBreak(
    position: number
): Interval

Parameters

NameTypeDescription
positionnumber

A position in the sub-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 sub-document.

Declaration

ts
insertPageBreak(
    position: number
): Interval

Parameters

NameTypeDescription
positionnumber

The position in the sub-document.

|

Returns

TypeDescription
Interval

The interval that contains the inserted page break.

|

insertParagraph(position) Method

Inserts a new paragraph into the paragraphs collection at a specified position.

Declaration

ts
insertParagraph(
    position: number
): Paragraph

Parameters

NameTypeDescription
positionnumber

A position to insert a new paragraph.

|

Returns

TypeDescription
Paragraph

The newly inserted paragraph.

|

insertPicture(position, base64) Method

Inserts a picture to the sub-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"); });

See Also

Examples

insertRtf(position, rtfText) Method

Inserts the specified RTF text at the specified position.

Declaration

ts
insertRtf(
    position: number,
    rtfText: string,
    callback?: (interval: Interval,
    isRtfValid: boolean) => void
): void

Parameters

NameTypeDescription
positionnumber

A position in the document.

| | rtfText | string |

The RTF text.

| | callback | (interval: Interval, isRtfValid: boolean) => void |

A function that is called after the RTF text is inserted.

|

Remarks

Use the insertRtf method to insert the RTF text at the specified sub-document position. After the insertion, RichEdit calls the callback function. If the inserted RTF is not valid, the isRtfValid parameter returns false.

If the rtfText parameter contains an entire document, the RichEdit control inserts the content of the main sub-document only.

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');

See Also

Common Use Cases: Text

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.

|

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.

|