Javascript: TXTextControl.saveDocument Method
Description
Saves the current document in a certain format and sends the result back asynchronously by calling a given callback function.
Syntax
<void> TXTextControl.saveDocument(<StreamType> streamType, <SaveDocumentResultCallback> callback, [<SaveSettings> saveSettings], [<ErrorCallback> errorCallback])Parameters
| Parameter | Description |
|---|---|
| streamType | Specifies one of the numerical StreamType values. |
| callback | A function with one parameter. Is called with an argument object of type SaveDocumentResult containing the document data after the document has been saved successfully. |
| saveSettings | Optional. Specifies additional save settings. |
| errorCallback | Optional. Is called when the operation failed with an error. |
Examples
The following example shows how to save the current document and display the received document data in the console.
TXTextControl.saveDocument(TXTextControl.StreamType.HTMLFormat, function (e) {
console.log(e.data);
});
Possible console output:
> <?xml version="1.0" ?>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
[...]The following example demonstrates TXTextControl.saveDocument in a practical document-editing workflow. It saves the current document in a certain format and sends the result back asynchronously by calling a given callback function.
function onTxError(error) {
console.error("TX Text Control error:", error.msg);
error.handled = true;
}
TXTextControl.saveDocument(
TXTextControl.StreamType.HTMLFormat,
function(args) {
if (!args) {
console.warn("No save document result was returned.");
return;
}
console.log("save document result:", args);
},
{ creatorApplication: "Document Editor sample" },
onTxError
);