Back to Devexpress

DocumentProcessorBase Class

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

latest11.3 KB
Original Source

DocumentProcessorBase Class

Implements the base functionality of a document processor.

Declaration

ts
export abstract class DocumentProcessorBase

Inheritance

DocumentProcessorBase DocumentProcessor

Properties

document Property

Provides access to document structural elements.

Declaration

ts
document: RichEditDocumentBase

Property Value

TypeDescription
RichEditDocumentBase

An object that lists a RichEdit document’s structural elements.

|

Remarks

javascript
var proc = richEdit.createDocumentProcessor();
proc.document.fields.create(proc.document.length, 'docvariable complexContent');
proc.document.fields.create(proc.document.length, 'docvariable text');
proc.document.fields.create(proc.document.length, 'docvariable complexContent');
proc.document.fields.create(proc.document.length, 'docvariable text');
proc.onCalculateDocumentVariable = function (s, e) {
    if (e.variableName == 'complexContent') {
        var docvarProc = richEdit.createDocumentProcessor();
        var picUrl = 'your-image-URL';
        var picSize = new DevExpress.RichEdit.Size(docvarProc.unitConverter.pixelsToTwips(200), docvarProc.unitConverter.pixelsToTwips(200));
        docvarProc.document.insertPicture(0, picUrl, picSize);
        docvarProc.document.insertText(docvarProc.document.length, 'Content1');
        docvarProc.document.setCharacterProperties(new DevExpress.RichEdit.Interval(1, 3), { bold: true });
        docvarProc.document.insertText(docvarProc.document.length, 'Content2');
        e.value = docvarProc;
    }
    if (e.variableName == 'text') {
        e.value = '!SimpelText!';
    }
}
proc.document.fields.updateAllFields(function () {
    proc.exportDocumentToBase64(function (base64) {
        proc.dispose();
        richEdit.openDocument(base64, 'someFile', DevExpress.RichEdit.DocumentFormat.OpenXml, (succ) => console.log(succ));
        }, DevExpress.RichEdit.DocumentFormat.OpenXml);
});

onCalculateDocumentVariable Property

Specifies an event handler to a client event that occurs when a DOCVARIABLE field is updated.

Declaration

ts
set onCalculateDocumentVariable(val: null | ((s: DocumentProcessorBase, e: CalculateDocumentVariableEventArgs) => void))

Property Value

TypeDescription
void

A function that handles the event. null to remove the event.

|

Remarks

The CalculateDocumentVariable event fires when a DOCVARIABLE value is calculated (when a field is updated, or during the mail merge process). Handle this event to analyze the DOCVARIABLE field name and arguments, and provide custom content to insert into this field.

The DOCVARIABLE field has the following structure: { DOCVARIABLE “variable name” “argument1” “argument 2”… }

javascript
var proc = richEdit.createDocumentProcessor();
proc.document.fields.create(proc.document.length, 'docvariable complexContent');
proc.document.fields.create(proc.document.length, 'docvariable text');
proc.document.fields.create(proc.document.length, 'docvariable complexContent');
proc.document.fields.create(proc.document.length, 'docvariable text');
proc.onCalculateDocumentVariable = function (s, e) {
    if (e.variableName == 'complexContent') {
        var docvarProc = richEdit.createDocumentProcessor();
        var picUrl = 'your-image-URL';
        var picSize = new DevExpress.RichEdit.Size(docvarProc.unitConverter.pixelsToTwips(200), docvarProc.unitConverter.pixelsToTwips(200));
        docvarProc.document.insertPicture(0, picUrl, picSize);
        docvarProc.document.insertText(docvarProc.document.length, 'Content1');
        docvarProc.document.setCharacterProperties(new DevExpress.RichEdit.Interval(1, 3), { bold: true });
        docvarProc.document.insertText(docvarProc.document.length, 'Content2');
        e.value = docvarProc;
    }
    if (e.variableName == 'text') {
        e.value = '!SimpelText!';
    }
}

unitConverter Property

Allows you to convert units.

Declaration

ts
readonly unitConverter: UnitConverter

Property Value

TypeDescription
UnitConverter

A unit converter object.

|

Remarks

javascript
var size = new DevExpress.RichEdit.Size(
    richEdit.unitConverter.centimetersToTwips(24),
    richEdit.unitConverter.centimetersToTwips(18));
richEdit.document.sections.getByIndex(0).pageSize = size;

Methods

dispose Method

Releases resources used by the document processor.

Declaration

ts
dispose(): void

Remarks

Note

If you create a document processor in the onCalculateDocumentVariable event handler, the processor is disposed automatically.

javascript
var proc = richEdit.createDocumentProcessor();
...
proc.dispose();

downloadDocument(fileName, documentFormat) Method

Downloads the current document.

Declaration

ts
downloadDocument(
    fileName: string,
    documentFormat: DocumentFormat
): void

Parameters

NameTypeDescription
fileNamestring

The name of the downloaded document.

| | documentFormat | DocumentFormat |

The document format.

|

downloadPdf(fileName) Method

Downloads the current document as a pdf file.

Declaration

ts
downloadPdf(fileName: string, options?: ((pdfDocument: any) => void) | {
    modifyPdfDocument?: (pdfDocument: any) => void;
    modifyPdfPage?: (pdfDocument: any) => void;
}): void

Parameters

NameTypeDescription
fileNamestring

The name of the downloaded document.

| | options | (pdfDocument: any) => void | {modifyPdfDocument: (pdfDocument: any) => void, modifyPdfPage: (pdfDocument: any) => void} |

A function that allows you to modify the PDF document before it is downloaded; or an object that contains modifyPdfDocument and modifyPdfPage functions.

|

Remarks

The downloadPdf method exports the document to the Portable Document Format (PDF) and downloads it to a local machine.

You can write a function to modify each page after it is exported ( modifyPdfPage ), or modify the document after the export is completed ( modifyPdfDocument ). The pdfDocument parameter is an object of the PDFKit library. If an export fails, the parameter returns null.

exportDocumentToBase64(callback) Method

Exports the current document in the specified format to base64.

Declaration

ts
exportDocumentToBase64(
    callback: (base64: string) => void,
    documentFormat?: DocumentFormat
): void

Parameters

NameTypeDescription
callback(base64: string) => void

A function that gets the base64 string as a parameter.

| | documentFormat | DocumentFormat |

The document format.

|

Remarks

The exportDocumentToBase64 method exports the current document to a base64 string. Use the documentFormat parameter to specify the document’s format. After export, the document processor calls the callback function and returns the base64 string as a parameter. You can use this function to save the exported document.

javascript
var proc = richEdit.createDocumentProcessor();
...
proc.document.fields.updateAllFields(function () {
    proc.exportDocumentToBase64(function (base64) {
        proc.dispose();
        richEdit.openDocument(base64, 'someFile', DevExpress.RichEdit.DocumentFormat.OpenXml, function (succ) { console.log(succ); });
    }, DevExpress.RichEdit.DocumentFormat.OpenXml);
});

exportDocumentToBlob(callback) Method

Exports the current document in the specified format to a blob.

Declaration

ts
exportDocumentToBlob(
    callback: (blob: Blob) => void,
    documentFormat?: DocumentFormat
): void

Parameters

NameTypeDescription
callback(blob: Blob) => void

A function that gets the blob as a parameter.

| | documentFormat | DocumentFormat |

The document format.

|

Remarks

The exportDocumentToBlob method exports the current document to a binary large object (blob). Use the documentFormat parameter to specify the document’s format. After export, the document processor calls the callback function and returns the blob as a parameter. You can use this function to save the exported document.

exportToPdf(callback) Method

Exports the current document to PDF.

Declaration

ts
exportToPdf(callback: (base64: string, blob: Blob, stream: any) => void, options?: ((pdfDocument: any) => void) | {
    modifyPdfDocument?: (pdfDocument: any) => void;
    modifyPdfPage?: (pdfDocument: any) => void;
}): void

Parameters

NameTypeDescription
callback(base64: string, blob: Blob, stream: any) => void

A function that gets the PDF document as a parameter.

| | options | (pdfDocument: any) => void | {modifyPdfDocument: (pdfDocument: any) => void, modifyPdfPage: (pdfDocument: any) => void} |

A function that allows you to modify the PDF document before it is downloaded; or an object that contains modifyPdfDocument and modifyPdfPage functions.

|

Remarks

The exportToPdf method exports the current document to the Portable Document Format (PDF). You can write a function to modify each page after it is exported ( modifyPdfPage ), or modify the document after the export is completed ( modifyPdfDocument ).

The pdfDocument parameter is an object of the PDFKit library. If an export fails, the parameter returns null.

The document processor sends the resulting PDF file in the base64, blob, and stream formats to the callback function. You can use the function to save the exported document.

Tip

Use the downloadPdf(fileName) method to download the current document as a PDF file.

importDocument(source, documentFormat, callback) Method

Imports a document from a base64 data or from a file.

Declaration

ts
importDocument(
    source: string | File,
    documentFormat: DocumentFormat,
    callback: (importSuccess: boolean) => void
): void

Parameters

NameTypeDescription
sourcestringFile

A document in a base64 format or a file object.

| | documentFormat | DocumentFormat |

The document format.

| | callback | (importSuccess: boolean) => void |

Allows you to perform custom actions after a file is imported.

|