Created
March 14, 2024 12:15
-
-
Save bjoerntx/0a15d89b7170eef610c0685e75654da7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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