Back to Devexpress

Utils Class

aspnetcore-js-devexpress-dot-richedit-16e5f5d7.md

latest8.0 KB
Original Source

Utils Class

Contains Rich Text Editor utility methods.

Declaration

ts
export class Utils

Methods

convertArrayBufferToBase64(content) Method

Converts the specified content from an ArrayBuffer object to a Base64 string.

Declaration

ts
static convertArrayBufferToBase64(
    content: ArrayBuffer
): string

Parameters

NameTypeDescription
contentArrayBuffer

The content to convert.

|

Returns

TypeDescription
string

The resulting Base64 string.

|

convertBase64ToArrayBuffer(content) Method

Converts the specified content from a Base64 string to an ArrayBuffer object.

Declaration

ts
static convertBase64ToArrayBuffer(
    content: string
): ArrayBuffer

Parameters

NameTypeDescription
contentstring

The content to convert.

|

Returns

TypeDescription
ArrayBuffer

The resulting ArrayBuffer object.

|

convertBlobToArrayBuffer(content, callback) Method

Converts the specified content to an ArrayBuffer object.

Declaration

ts
static convertBlobToArrayBuffer(
    content: File | Blob,
    callback: (buffer: ArrayBuffer) => void
): void

Parameters

NameTypeDescription
contentFileBlob

The content to convert.

| | callback | (buffer: ArrayBuffer) => void |

The resulting ArrayBuffer object.

|

convertBlobToBase64(content, callback) Method

Converts the specified content from a File or Blob object to a Base64 string.

Declaration

ts
static convertBlobToBase64(
    content: File | Blob,
    callback: (base64: string) => void
): void

Parameters

NameTypeDescription
contentFileBlob

The content to convert.

| | callback | (base64: string) => void |

The resulting Base64 string.

|

convertToBlob(content) Method

Converts the specified content to a Blob object.

Declaration

ts
static convertToBlob(
    content: File | ArrayBuffer | string,
    options?: BlobPropertyBag
): Blob

Parameters

NameTypeDescription
contentstringFile

The content to convert.

| | options | BlobPropertyBag |

An object that contains Blob object properties.

|

Returns

TypeDescription
Blob

The resulting Blob object.

|

convertToFile(content) Method

Converts the specified content to a File object.

Declaration

ts
static convertToFile(
    content: Blob | ArrayBuffer | string,
    fileName?: string,
    options?: FilePropertyBag
): File

Parameters

NameTypeDescription
contentstringBlob

The content to convert.

| | fileName | string |

The name of the converted file.

| | options | FilePropertyBag |

An object that contains File object properties.

|

Returns

TypeDescription
File

The resulting File object.

|

documentFormatToExtension(documentFormat) Method

Returns a document extension that matches the specified document format.

Declaration

ts
static documentFormatToExtension(
    documentFormat: DocumentFormat
): string

Parameters

NameTypeDescription
documentFormatDocumentFormat

The document format.

|

Returns

TypeDescription
string

The document extension.

|

Remarks

javascript
//returns ".txt"
DevExpress.RichEdit.Utils.documentFormatToExtension(DevExpress.RichEdit.DocumentFormat.PlainText);

download(content, fileName) Method

Downloads a file with the specified content to a local machine.

Declaration

ts
static download(
    content: File | Blob | ArrayBuffer | string,
    fileName: string
): void

Parameters

NameTypeDescription
contentstringFile

The file content.

| | fileName | string |

The name of the downloaded file.

|

Remarks

javascript
//download the first image in the Rich Text Editor
var img = richEdit.document.images.getAllImages()[0];
DevExpress.RichEdit.Utils.download(img.base64, 'imageName' + img.extension);

//download the selected content as an RTF file
if(richEdit.selection.intervals[0].length > 0 && richEdit.selection.intervals.length == 1) {
    var rtf = richEdit.selection.activeSubDocument.getRtf(richEdit.selection.intervals[0]);
    DevExpress.RichEdit.Utils.download(btoa(rtf), 'docName.rtf');
}

getDocumentFormat(filePath) Method

Returns the file’s document format.

Declaration

ts
static getDocumentFormat(
    filePath: string
): DocumentFormat | null

Parameters

NameTypeDescription
filePathstring

The path to the file.

|

Returns

TypeDescription
DocumentFormat

The document format. null if the file does not match any document format.

|

getIntervalComplement(bound, intervals) Method

Returns document intervals that contain the difference between the bound interval and given intervals.

Declaration

ts
static getIntervalComplement(
    bound: Interval,
    intervals: Interval[]
): Interval[]

Parameters

NameTypeDescription
boundInterval

The bound interval.

| | intervals | Interval[] |

The intervals that should be subtracted.

|

Returns

TypeDescription
Interval[]

The result intervals.

|

Remarks

Use the getIntervalComplement method to get intervals that complement the specified intervals in the boundaries.

javascript
var boundInterval = {start: 0, length: 10};
var initialIntervals = [{start: 1, length: 1},{start: 5, length: 2}];
// returns 3 intervals: {start: 0, length: 1},{start: 2, length: 3},{start: 7, length: 3}
DevExpress.RichEdit.Utils.getIntervalComplement(boundInterval,initialIntervals);

The code sample below changes foreground color of unselected text in the main document to light gray.

javascript
DemoRichEdit.history.beginTransaction();
var complementIntervals = DevExpress.RichEdit.Utils.getIntervalComplement(
  DemoRichEdit.document.interval, DemoRichEdit.selection.intervals
);
complementIntervals.forEach(function(interval){
  DemoRichEdit.document.setCharacterProperties(interval, { foreColor: 'lightgray' });
});
DemoRichEdit.history.endTransaction();

parseFilePath(filePath) Method

Parses a file path and returns an object that contains information about the path’s parts, such as name, document format, and directory path.

Declaration

ts
static parseFilePath(
    filePath: string
): IFilePathInfo

Parameters

NameTypeDescription
filePathstring

The path to the document to parse.

|

Returns

TypeDescription
IFilePathInfo

An object that contains information about the parsed file path.

|

Remarks

javascript
var filePath = 'C:/Users/Public/Documents/Example.docx';
var fileInfo = DevExpress.RichEdit.Utils.parseFilePath(filePath);
fileInfo.directoryPath; //returns 'C:/Users/Public/Documents'
fileInfo.documentFormat; //returns DevExpress.RichEdit.DocumentFormat.OpenXml
fileInfo.extension; //returns '.docx'
fileInfo.name; //returns 'Example.docx'
fileInfo.nameWithoutExtension; //returns 'Example'
fileInfo.path; //returns 'C:/Users/Public/Documents/Example.docx'