I need to read file (.doc) then replace some data in doc and then send to print (doc or pdf).
At first step I try to read data from docs. From .txt its work, but from .doc no :(
I did example in jsfiddle http://jsfiddle.net/qo0fxo50/
I try to do it like:
<h1>Select file</h1>
<input type="file" on-read-file="showContent($fileContent)" />
<div>
<h2>File content is:</h2>
<pre>{{ contentfile }}</pre>
</div>
And directive (on-read-file):
directives.directive('onReadFile', function ($parse) {
return {
restrict: 'A',
scope: false,
link: function(scope, element, attrs) {
var fn = $parse(attrs.onReadFile);
element.on('change', function(onChangeEvent) {
var reader = new FileReader();
reader.readAsText((onChangeEvent.target).files[0], 'CP1251');
reader.onload = function(onLoadEvent) {
scope.$apply(function() {
fn(scope, {$fileContent:onLoadEvent.target.result});
});
};
});
}
};
});
I did example in jsfiddle http://jsfiddle.net/qo0fxo50/
.doc is a proprietary and binary format (also there are multiple incompatible versions). That means it's a bunch of undocumented bytes instead of some charackters as with .txt.
You won't get anything out of it unless you understand the details of that format or find a library that helps you to read it. I'd suggest automate '.doc-contents to something you can parse'-conversion with a tool (there should be something out there, but don't exspect accurate results) or even better don't use .doc.
As for the new .docx formats it should be a little easier to get contents, as they are basically .xml.
©2020 All rights reserved.