10

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?

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
Tomasz Zieliński
  • 16,136
  • 7
  • 59
  • 83
  • The reason it breaks out of iframe, is that google don't license for that use – TFD Feb 15 '10 at 08:27
  • Why the close vote? The answer that google doesn't license for embedding is perfectly valid answer if supported by relevant excerpt from EULA. But if google provides embeddable pdf viewer then it's probably meant for being embedded, isn't it? – Tomasz Zieliński Feb 15 '10 at 08:53
  • Is there anyway you can use google viewer to avoid users from saving it to their google account by passing certain variables? – ApPeL Jul 08 '11 at 08:59
  • @ApPel: I'm not sure what you mean, and also I haven't touched Google viewer for the last year or so - so a lot of things could have changed meanwhile. Maybe others know the answer to your question. – Tomasz Zieliński Jul 09 '11 at 09:35
  • @Thomas, thanks for the reply, ended up with going with Scribd as a solution. – ApPeL Jul 27 '11 at 14:23

6 Answers6

11

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: https://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html, that can be used like this:

  <iframe src="https://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.

K J
  • 8,045
  • 3
  • 14
  • 36
Tomasz Zieliński
  • 16,136
  • 7
  • 59
  • 83
7

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>
Deepak Yadav
  • 1,724
  • 3
  • 23
  • 38
  • It doesn't work. It says the document isn't available. P.S. The document must be accessed by Everyone in order to be embeddable. – Royi May 24 '10 at 23:48
  • 1
    yes you are right I forgot to mention that thing. Document has to be shared to everyone in order for that to work. – Deepak Yadav Sep 03 '10 at 15:58
5

Try this!

Same as other answers above...

<iframe src="https://docs.google.com/gview?url={magical url that works}"></iframe>

except the magical url that works is https://drive.google.com/uc?id=<docId>&embedded=true.


Google Drive/Docs provides a bunch of different urls:

  • https://drive.google.com/open?id=<docId> Share link.
  • https://docs.google.com/document/<docId>/edit Open in Google Drive.
  • https://docs.google.com/document/d/<docId>/view Same as 'edit' above. I think.
  • https://docs.google.com/document/d/<docId>/pub?embedded=true For embedding in iframe if you File -> Publish to the web...
  • https://drive.google.com/uc?export=download&id=<docId> Direct download link.

I stumbed across this solution after a bunch of trial and error with different links. Hope this helps!

Derek Soike
  • 11,238
  • 3
  • 79
  • 74
0

The Google Docs embedding in iframes via the viewer is problematic in IE8 if not already cached, and is is just not equal to the much better Scribd's facility that allows you to simply make a simple html page with the document embeded via their supplied object code for the document. I then use it as the source file for my iframe. It shows the print (and also a full screen button), right in the embedded frame page. Much more friendly and reliable for the page's visitors.

dawall
  • 1
  • 2
0

The following worked for me:

<iframe src="https://drive.google.com/viewerng/viewer?url=url_of_pdf?pid=explorer&efh=false&a=v&chrome=false&embedded=true" embedded=true></iframe>
-1

Spent an hour on this, below worked:

Example:

<iframe src={`https://docs.google.com/gview?url=${encodeURIComponent('http://infolab.stanford.edu/pub/papers/google.pdf')}&embedded=true`}></iframe>

Note that encodeURIComponent was needed.

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140