Last active
May 25, 2017 15:59
-
-
Save bjoerntx/130eaf8cee57554a24f1 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
// ***************************************************************** | |
// 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