Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed Google Docs PDF viewer in IFRAME

When I upload PDF to Google Docs (using Python's gdata library), I get link to the document:

>>> e.GetAlternateLink().href
Out[14]: 'http://docs.google.com/a/my.dom.ain/fileview id=<veery-long-doc-id>&hl=en'

Unfortunately using that link in IFRAME is not working for me because PDF viewer is redirecting to itself, breaking out of IFRAME.

Looking for the solution, I've found this: http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html - which looks very nice, but I can't find a way to use it with document uploaded to Google Docs. Does somebody know how to do it/if it's at all possible?

like image 374
Tomasz Zieliński Avatar asked Feb 15 '10 08:02

Tomasz Zieliński


People also ask

Can you iframe a Google Doc?

Open your Google Document (or other Google item). Under the "File" menu, click "Publish to the Web". Copy the "iframe" code. On the page you want the Google Doc embedded, click on "Source Code" button from the WYSIWYG editor to open the HTML editor.

How do I use Google Docs viewer in HTML?

Google Docs Viewer is a web application that can open all your Internet documents directly from your web browser. To use it, all you have to do is visit http://docs.google.com/viewer and enter the document URL. You don't even have to log into a Google account.

Can you embed a PDF in a Google Doc?

Log into Google Drive. Click on the New button on the left side of your screen and select File Upload. Find your PDF file and upload it. Once it's uploaded, click on it and select Open With Google Docs to turn it into an editable file.


2 Answers

Just for the record - I haven't found any way to force "internal" google google pdf viewer to not go out of the iframe. And as I mentioned in the question, I found this nice standalone viewer: http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html, that can be used like this:

  <iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

-- but in order to use it you have to publish your PDF to the outside world. This wouldn't be a bad solution, because published document has unique id that is probably harder to guess than a password to google docs account. Unfortunately, even with hottest Google Docs API version 3 API, there seems to be no way of publishing PDF programatically..

In the end, I went for a mix of: standalone PDF viewer from google and some other web service that allows to programatically upload and publish PDF. A bit half-baked solution, but it works well so far.

like image 120
Tomasz Zieliński Avatar answered Sep 23 '22 09:09

Tomasz Zieliński


To embed pdf files present in your google docs into your website use the below code:

<iframe src="http://docs.google.com/gview?a=v&pid=explorer&chrome=false&api=true&embedded=true&srcid=<id of your pdf>&hl=en&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
like image 32
Deepak Yadav Avatar answered Sep 23 '22 09:09

Deepak Yadav