After much research, I found the best solution for displaying almost all types of documents in a browser using an iframe.
Solution - Google Docs Viewer
Just use an iframe as below, and replace the document URL in it.
<iframe src='https://docs.google.com/viewer?url=ENTER URL OF YOUR DOCUMENT HERE&embedded=true' frameborder='0'></iframe>
By replacing the sample URL for the .docx file, the above code becomes.
<iframe src='https://docs.google.com/viewer?url=http://calibre-ebook.com/downloads/demos/demo.docx&embedded=true' frameborder='0'></iframe>
By replacing the sample URL for the .pdf file, the above code becomes.
<iframe src='https://docs.google.com/viewer?url=http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf&embedded=true' frameborder='0'></iframe>
Note. The document that needs to be displayed in the browser must have the correct URL and must be publicly accessible , since Google needs to get and display the document, the process will fail if the document is private, and you will see an iframe without PRELIMINARY VIEWING AVAILABLE
Aamir source share