Embed Google Docs PDF viewer in IFRAME

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.


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>

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!