Skip to main content

Utils Class

Contains Rich Text Editor utility methods.

Declaration

export class Utils

Methods

convertArrayBufferToBase64(content) Method

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

Declaration

static convertArrayBufferToBase64(
    content: ArrayBuffer
): string

Parameters

Name Type Description
content ArrayBuffer

The content to convert.

Returns

Type Description
string

The resulting Base64 string.

convertBase64ToArrayBuffer(content) Method

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

Declaration

static convertBase64ToArrayBuffer(
    content: string
): ArrayBuffer

Parameters

Name Type Description
content string

The content to convert.

Returns

Type Description
ArrayBuffer

The resulting ArrayBuffer object.

convertBlobToArrayBuffer(content, callback) Method

Converts the specified content to an ArrayBuffer object.

Declaration

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

Parameters

Name Type Description
content File | Blob

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

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

Parameters

Name Type Description
content File | Blob

The content to convert.

callback (base64: string) => void

The resulting Base64 string.

convertToBlob(content) Method

Converts the specified content to a Blob object.

Declaration

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

Parameters

Name Type Description
content string | File | ArrayBuffer

The content to convert.

options BlobPropertyBag

An object that contains Blob object properties.

Returns

Type Description
Blob

The resulting Blob object.

convertToFile(content) Method

Converts the specified content to a File object.

Declaration

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

Parameters

Name Type Description
content string | Blob | ArrayBuffer

The content to convert.

fileName string

The name of the converted file.

options FilePropertyBag

An object that contains File object properties.

Returns

Type Description
File

The resulting File object.

documentFormatToExtension(documentFormat) Method

Returns a document extension that matches the specified document format.

Declaration

static documentFormatToExtension(
    documentFormat: DocumentFormat
): string

Parameters

Name Type Description
documentFormat DocumentFormat

The document format.

Returns

Type Description
string

The document extension.

Remarks

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

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

Parameters

Name Type Description
content string | File | Blob | ArrayBuffer

The file content.

fileName string

The name of the downloaded file.

Remarks

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

static getDocumentFormat(
    filePath: string
): DocumentFormat | null

Parameters

Name Type Description
filePath string

The path to the file.

Returns

Type Description
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

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

Parameters

Name Type Description
bound Interval

The bound interval.

intervals Interval[]

The intervals that should be subtracted.

Returns

Type Description
Interval[]

The result intervals.

Remarks

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

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.

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

static parseFilePath(
    filePath: string
): IFilePathInfo

Parameters

Name Type Description
filePath string

The path to the document to parse.

Returns

Type Description
IFilePathInfo

An object that contains information about the parsed file path.

Remarks

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'