在IFRAME中嵌入Google文档PDF查看器

时间:2010-02-15 08:18:32

标签: python gdata-api google-docs

当我将PDF上传到Google文档时(使用Python的gdata库),我获得了该文档的链接:

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

不幸的是,在IFRAME中使用该链接对我不起作用,因为PDF查看器会重定向到自身,从而突破IFRAME。

寻找解决方案,我发现了这个问题:http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html - 看起来很不错,但我无法找到将其用于上传到Google文档的文档的方法。有人知道怎么做/如果可能吗?

5 个答案:

答案 0 :(得分:7)

仅供记录 - 我还没有找到任何方法强制“内部”google google pdf viewer不要离开iframe。正如我在问题中提到的,我找到了这个漂亮的独立查看器:http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html,可以像这样使用:

  <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>

- 但为了使用它,您必须将PDF发布到外部世界。这不是一个糟糕的解决方案,因为发布的文档具有唯一ID,可能比谷歌文档帐户的密码更难猜测。不幸的是,即使使用最热门的Google Docs API第3版API,也似乎无法以编程方式发布PDF。

最后,我选择了谷歌的独立PDF查看器和其他一些允许以编程方式上传和发布PDF的网络服务。有点半生不熟的解决方案,但到目前为止效果很好。

答案 1 :(得分:3)

要将google文档中包含的pdf文件嵌入您的网站,请使用以下代码:

<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>

答案 2 :(得分:1)

如果尚未缓存,则通过查看器嵌入iframe中的Google Docs在IE8中存在问题,并且不等于更好的Scribd工具,它允许您简单地创建一个简单的html页面,其中包含通过其提供的文档嵌入文档的目标代码。然后我将它用作我的iframe的源文件。它在嵌入式框架页面中显示打印(以及全屏按钮)。对于页面的访问者来说,它更加友好和可靠。

答案 3 :(得分:0)

试一试!

与上述其他答案相同......

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

magical url that workshttps://drive.google.com/uc?id=<docId>&embedded=true

Google Drive / Docs提供了许多不同的网址:

  • https://drive.google.com/open?id=<docId>分享链接。
  • https://docs.google.com/document/<docId>/edit在Google云端硬盘中开启。
  • https://docs.google.com/document/d/<docId>/view与&#39;编辑&#39;相同以上。我想。
  • https://docs.google.com/document/d/<docId>/pub?embedded=true如果您File -> Publish to the web...
  • ,则嵌入iframe
  • https://drive.google.com/uc?export=download&id=<docId>直接下载链接。

在经过一系列不同链接的试错之后,我绊倒了这个解决方案。希望这可以帮助!

答案 4 :(得分:0)

以下对我有用:

<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>
相关问题