Document Viewer (doc or docx ) from byte array in angular 4

2.5k views Asked by At

I have a requirement to view all the attachments submitted by the end user. I am able to view the pdf and image files but I am not able to view the files with doc or docx extension. This is what I have done.

let file = null;
  if (extension === 'pdf') {
    file = new Blob([new Uint8Array(byteFile)], { type: 'application/pdf' });
  } else if (extension === 'jpg' || extension === 'png') {
    file = new Blob([new Uint8Array(byteFile)], { type: 'image/png' });
  } else {
    file = new Blob([new Uint8Array(byteFile)], { type: 'application/msword' });
  }
  if (file !== null) {
    const fileURL = URL.createObjectURL(file);
    window.open(fileURL, fileName);
  }

The above code works fine for pdf and image files in chrome and firefox (doesnot work for IE ) .However for doc or docx it does not work in any browser.Can any one tell me what should I do

1

There are 1 answers

0
Joshua Shane Martin On

You could use a thumbnail generation service like Post2Preview. It can generate a file preview of many popular, proprietary formats. Disclosure: I work for Post2Preview