I have just installed mammoth.browser.min (v. 1.2.0) and, using an HTML tag as shown in the docs, tested it successfully on .docx files to be displayed in the browser.
Then I tried to implement parseWordDocxFile through a different interface: after loading files onto a server using $.post, I display them as a list. From this list, any line can be double-clicked like so:
let myFile = {"reference": reference, "type": type};
openDocument (myFile);
" reference " and "type" are retrieved from a $.get request: "reference" is the full path to the intended file; "type" is the file type.
The signature of the callee is openDocument (theFile). This function includes a switch:
switch (theFile.type)
{
case 'pdf': case 'PDF': case 'PNG': case 'png': case 'JPEG': case 'jpg': case 'JPG':
window.open ( file.reference ); // browser handles it directly
break;
case 'docx': parseWordDocxFile(file.reference); break; // full path to the file, checked
}
For file types .pdf, .png, .jpg, is works smoothly.
Now, as to .docx files, it avails to nothing. Upon entering parseWordDocxFile, Debugger says:
TypeError: FileReader.readAsArrayBuffer: Argument 1 is not an object
BUT if I copy back the file from the server onto my local disk and try and open it with the HTML interface (ditto), it works. In other words there is nothing wrong with the file stored on the server.
I surmise that I might pass parseWordDocxFile(theFile) an file object like so:
var objFile = new File ( [data], // type:= []
"Sample.docx", // full path correct
{
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", // type displayed on debugging
lastModified: 1650875824000
}
but I have no clue as to what data would be.
What is it I am doing wrong? What is the right way to get it working?