'View PDF or MS Office documents inside an iframe
I am trying to display different kinds of files inside a iframe. It works for text, images and pdf files but not working with MS office or Open office documents. Is there a way to do this? Also, it automatically starts to download files that cannot be opened, is there a way to stop this automatic download from happening?
Solution 1:[1]
Microsoft now provides a nice web viewer, explained here
It only works on files that are publicly available at some http endpoint, but thankfully, they do let you stick it an the iframe. Just append your filename as the src of this link:
view.officeapps.live.com/op/view.aspx?src=
A more interesting solution to me is to look around for ways to use open office on the command line. It has a capability to convert microsoft documents into open office format, at which point you can use the open source http://viewerjs.org/ and host it yourself if that's your style.
Solution 2:[2]
Just make the src attribute in your IFrame refer to a direct link for the PDF, such as
https://docs.google.com/viewer?embedded=true&url={DirectPdfUrl}, where DirectPdfUrl is a direct link to the PDF file (must be accessible over the internet, not locally!)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Colten Jackson |
| Solution 2 |
