I was looking for a way to let users see Microsoft Word Doc or PDF files online while using my application without leaving their browser without downloading files and then opening it to view with Word or PDF viewer. I was looking for some way out either via any PHP or Microsoft.NET libraries, did some googling on that; but later on I just got an idea that google already has all code written for me.. when I have any email attachment in PDF or DOC or DOCX google does it for me..! Even while searching I can see PDFs by converting them in HTML. So I just googled it up and found that Google already has this ability that we can use Google Docs Viewer without any Google Account Login. YES that's true no Google Account login is required. It's damn simple and easy. Just pass document path as attachment as parameter and we are done.
Google Docs Viewer gives us ability to embed PDF, DOC/DOCX, PPT, TIFF:
Yes that's true; Google Docs Viewer gives us ability to view/embed functionality of PDF, DOC/DOCX, PPT and TIFF viewing on the fly without writing a single line of code by just giving a link or embedding within. No PPTX or XLS/XLSX is supported, but hopefully it should be coming in future.. But the document types which are supported are well enough and TIFF viewing ability is excellent and so if we have some requirement of letting users view TIFF files we don't need them to use any browser plugin or additional software to do that. This service was made available in September 2009.
All viewer URLs should use the path http://docs.google.com/viewer. This path accepts two parameters: url : The URL of the document to view. This should be URL-encoded. embedded : If set to true , the viewer will use an embedded mode interface. http://docs.google.com/viewer?url=<URL_OF_DOCUMENT> or http://docs.google.com/viewer?url=<URL_OF_DOCUMENT>&embedded=true
You can follow this link to see how document would look like in non-embedded mode.
Sample PDF document (in non-embedded/full mode)
Embedded view is available just right below (using IFRAME):
Sample code used for embedded viewer:
<iframe style="border-style: none;" src="http://docs.google.com/viewer?url=http%3A%2F%2Fblogs.digitss.com%2Fwp-content%2Fuploads%2F2010%2F01%2Fsample.pdf&embedded=true" height="390" width="400"></iframe>
Caching and Performance:
Yes, Google Docs Viewer does cache documents for performance reasons; I don't know how long exactly but it does. Now if we don't want caching then we can just use the same trick we do for refreshing our static contents sometime. We can pass time-stamp in query-string and Google Docs Viewer will consider it as different document and it will be your updated docuemnt with same name and URL path.
I have observed that PDF files have performed better; mean that they really get being read by viewer faster than Doc/PPT files.
Please share your experience of using GDV (Google Doc Viewer) or any other Online Document Viewer service/tool you have used.
View original Google Docs Blog post: http://googledocs.blogspot.com/2009/09/view-online-files-using-google-docs.html
#1 by Ernesto on January 30, 2010 - 8:54 pm
Quote
This is waaayyy too nice!! But what’s to view of google? they agree with that? can we use that service without their tipical registration?
#2 by Dharmavirsinh Jhala on January 31, 2010 - 4:39 am
Quote
Hi Ernesto,
It's all legal and this Google Docs Viewer service is publicly available.
Check this out. http://docs.google.com/viewer?pli=1
#3 by Ernesto on February 2, 2010 - 3:48 am
Quote
Thank you for the info…. nice blog! keep it up.
#4 by Mobin Molai on February 18, 2010 - 5:30 am
Quote
This is an excellent way of embedding online document viewer within your website. Thanks for the technique.
#5 by shivaganesh on July 15, 2010 - 12:35 pm
Quote
Is it work for excel file?
#6 by Dharmavirsinh Jhala on July 22, 2010 - 2:48 am
Quote
No. Not for excel so far.
#7 by varun on November 18, 2010 - 3:52 pm
Quote
i am getting error:"sorry, we are unable to retrieve the document for viewing"
Could anyone help?
#8 by Dharmavirsinh Jhala on November 18, 2010 - 11:58 pm
Quote
Varun,
You must make sure that your document should be available openly on Internet.
For example any URL you provide on Google Docs Viewer must be on the Internet w/o any security..
I hope you are not trying from VPN or LAN.
Good Luck.
#9 by Conor Cleary on December 1, 2010 - 10:06 pm
Quote
Hi there,
I have been using GDV for a months months to display a PDF that changes weekly – it works great.
However, it does not display properly on some of the university computers unless you click 'Fit to Screen'. (Otherwise it only shows the last page of the doc) Is there a url parameter or otherwise that will enable this upon loading?
Thanks!
#10 by Dharmavirsinh Jhala on December 2, 2010 - 12:47 am
Quote
I have not faced this problem but what you can try is you can put a random string after your document path like http://example.com/path-to-your-doc/document.pdf?… or something like this.
Let me know if it works out.!
#11 by Shrikant on December 2, 2010 - 5:18 pm
Quote
Hello
Nice work but this code is not working for MS word file.
Do you have any solution for this?
Pleae help me.
shrikantdhyani@1softsolutions.co.uk
Thanks
#12 by Dharmavirsinh Jhala on December 2, 2010 - 11:22 pm
Quote
Shrikant,
You can try by saving it as .docx file type, it should work for sure for docx.
If it does not work you can send your doc file sample to me at dharmavir [at] gmail [dot] com
#13 by jerome on November 23, 2011 - 1:27 pm
Quote
Any idea how to style the interface — specifically, I'd like to remove the padding from around an embedded PDF and maybe change the ui at the top of it if possible? Thanks!
#14 by Dharmavirsinh Jhala on January 15, 2012 - 10:14 pm
Quote
Look if there is any parameters to embed code is available, I guess not much.
#15 by Phalla on January 18, 2012 - 1:35 pm
Quote
How can we use for intranet web-based application with php?
#16 by Dharmavirsinh Jhala on January 30, 2012 - 12:57 pm
Quote
Hi Phalla,
It won't be possible to use this with Intranet application unless you can provide a static IP or domain to that file for google to access.
Because Google Docs viewer can work only when you can make that file available to Google publicly.
Try googling you should find some other solutions which can help you show that, I know of http://www.knowledgetree.com/ which offers document reading or searching and is php based opensource + commercial edition, you can try downloading opensource edition to see how it works. I tried that long back and it was some opensource libraries which they used probably in combination with openoffice or something.
Hope this helps.
Good Luck…
#17 by Dharmavirsinh Jhala on February 13, 2011 - 12:06 pm
Quote
It should not ask for login, if possible show me the code you’re using to embed the docs.