Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active May 25, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bjoerntx/130eaf8cee57554a24f1 to your computer and use it in GitHub Desktop.
Save bjoerntx/130eaf8cee57554a24f1 to your computer and use it in GitHub Desktop.
// *****************************************************************
// readDocument
//
// Desc: This function reads a file, converts it to a Base64 encoded
// string and loads it into TX Text Control
//
// param input: The input HTML element
// *****************************************************************
function readDocument(input) {
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]);
}
}
// call readDocument when a new document has been selected
$("#fileinput").change(function () {
readDocument(this);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment