Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created December 6, 2019 19:24
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/eb1c5f77cecfb5a1718a271c5101c8e0 to your computer and use it in GitHub Desktop.
Save bjoerntx/eb1c5f77cecfb5a1718a271c5101c8e0 to your computer and use it in GitHub Desktop.
function saveDocument() {
TXTextControl.saveDocument(TXTextControl.StreamType.AdobePDF, function (e) {
bDocument = e.data;
var element = document.createElement('a');
element.setAttribute('href', 'data:application/octet-stream;base64,' + e.data);
element.setAttribute('download', "document.pdf");
element.style.display = 'none';
document.body.appendChild(element);
// simulate click
element.click();
// remove the link
document.body.removeChild(element);
});
}
function readDocument(input) {
input = input.srcElement;
if (input.files && input.files[0]) {
var fileReader = new FileReader();
fileReader.onload = function (e) {
var streamType = TXTextControl.streamType.PlainText;
// set the StreamType based on the lower case extension
switch (fileinput.value.split('.').pop().toLowerCase()) {
case 'doc':
streamType = TXTextControl.streamType.MSWord;
break;
case 'docx':
streamType = TXTextControl.streamType.WordprocessingML;
break;
case 'rtf':
streamType = TXTextControl.streamType.RichTextFormat;
break;
case 'htm':
streamType = TXTextControl.streamType.HTMLFormat;
break;
case 'tx':
streamType = TXTextControl.streamType.InternalUnicodeFormat;
break;
case 'pdf':
streamType = TXTextControl.streamType.AdobePDF;
break;
}
// load the document beginning at the Base64 data (split at comma)
TXTextControl.loadDocument(streamType, e.target.result.split(',')[1]);
};
// read the file and convert it to Base64
fileReader.readAsDataURL(input.files[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment