Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created March 14, 2024 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/0a15d89b7170eef610c0685e75654da7 to your computer and use it in GitHub Desktop.
Save bjoerntx/0a15d89b7170eef610c0685e75654da7 to your computer and use it in GitHub Desktop.
async function saveDocument(StreamType) {
// save document
return new Promise((resolve, reject) => {
TXTextControl.saveDocument(StreamType, function (e) {
if (e) {
resolve(e.data);
} else {
reject('Error saving document');
}
});
});
}
function loadDocumentFromUrl(url) {
// download document using xml http request
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status === 200) {
var blob = xhr.response;
var reader = new FileReader();
reader.onload = function () {
// get the base64 encoded string
var base64 = reader.result.split(',')[1];
// load the document
TXTextControl.loadDocument(TXTextControl.StreamType.InternalUnicodeFormat, base64);
};
reader.readAsDataURL(blob);
}
};
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment