aspnetcore-js-devexpress-dot-richedit-16e5f5d7.md
Contains Rich Text Editor utility methods.
export class Utils
Converts the specified content from an ArrayBuffer object to a Base64 string.
static convertArrayBufferToBase64(
content: ArrayBuffer
): string
| Name | Type | Description |
|---|---|---|
| content | ArrayBuffer |
The content to convert.
|
| Type | Description |
|---|---|
| string |
The resulting Base64 string.
|
Converts the specified content from a Base64 string to an ArrayBuffer object.
static convertBase64ToArrayBuffer(
content: string
): ArrayBuffer
| Name | Type | Description |
|---|---|---|
| content | string |
The content to convert.
|
| Type | Description |
|---|---|
| ArrayBuffer |
The resulting ArrayBuffer object.
|
Converts the specified content to an ArrayBuffer object.
static convertBlobToArrayBuffer(
content: File | Blob,
callback: (buffer: ArrayBuffer) => void
): void
| Name | Type | Description |
|---|---|---|
| content | File | Blob |
The content to convert.
| | callback | (buffer: ArrayBuffer) => void |
The resulting ArrayBuffer object.
|
Converts the specified content from a File or Blob object to a Base64 string.
static convertBlobToBase64(
content: File | Blob,
callback: (base64: string) => void
): void
| Name | Type | Description |
|---|---|---|
| content | File | Blob |
The content to convert.
| | callback | (base64: string) => void |
The resulting Base64 string.
|
Converts the specified content to a Blob object.
static convertToBlob(
content: File | ArrayBuffer | string,
options?: BlobPropertyBag
): Blob
| Name | Type | Description |
|---|---|---|
| content | string | File |
The content to convert.
| | options | BlobPropertyBag |
An object that contains Blob object properties.
|
| Type | Description |
|---|---|
| Blob |
The resulting Blob object.
|
Converts the specified content to a File object.
static convertToFile(
content: Blob | ArrayBuffer | string,
fileName?: string,
options?: FilePropertyBag
): File
| Name | Type | Description |
|---|---|---|
| content | string | Blob |
The content to convert.
| | fileName | string |
The name of the converted file.
| | options | FilePropertyBag |
An object that contains File object properties.
|
| Type | Description |
|---|---|
| File |
The resulting File object.
|
Returns a document extension that matches the specified document format.
static documentFormatToExtension(
documentFormat: DocumentFormat
): string
| Name | Type | Description |
|---|---|---|
| documentFormat | DocumentFormat |
The document format.
|
| Type | Description |
|---|---|
| string |
The document extension.
|
//returns ".txt"
DevExpress.RichEdit.Utils.documentFormatToExtension(DevExpress.RichEdit.DocumentFormat.PlainText);
Downloads a file with the specified content to a local machine.
static download(
content: File | Blob | ArrayBuffer | string,
fileName: string
): void
| Name | Type | Description |
|---|---|---|
| content | string | File |
The file content.
| | fileName | string |
The name of the downloaded file.
|
//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');
}
Returns the file’s document format.
static getDocumentFormat(
filePath: string
): DocumentFormat | null
| Name | Type | Description |
|---|---|---|
| filePath | string |
The path to the file.
|
| Type | Description |
|---|---|
| DocumentFormat |
The document format. null if the file does not match any document format.
|
Returns document intervals that contain the difference between the bound interval and given intervals.
static getIntervalComplement(
bound: Interval,
intervals: Interval[]
): Interval[]
| Name | Type | Description |
|---|---|---|
| bound | Interval |
The bound interval.
| | intervals | Interval[] |
The intervals that should be subtracted.
|
| Type | Description |
|---|---|
| Interval[] |
The result intervals.
|
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();
Parses a file path and returns an object that contains information about the path’s parts, such as name, document format, and directory path.
static parseFilePath(
filePath: string
): IFilePathInfo
| Name | Type | Description |
|---|---|---|
| filePath | string |
The path to the document to parse.
|
| Type | Description |
|---|---|
| IFilePathInfo |
An object that contains information about the parsed file path.
|
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'