在 IFRAME 中嵌入 Google Docs PDF 查看器

发布于 2024-08-22 07:07:55 字数 566 浏览 2 评论 0原文

当我将 PDF 上传到 Google Docs(使用 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 文档的文档一起使用的方法。有人知道怎么做/如果可能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

挽清梦 2024-08-29 07:07:55

只是为了记录 - 我还没有找到任何方法来强制“内部”google google pdf 查看器不走出 iframe。正如我在问题中提到的,我发现了这个不错的独立查看器: https://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html,可以像这样使用:

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

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

最后,我选择了以下组合:来自 google 的独立 PDF 查看器和其他一些允许以编程方式上传的 Web 服务并发布 PDF。有点不成熟的解决方案,但到目前为止效果很好。

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.

夜唯美灬不弃 2024-08-29 07:07:55

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

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>
甜警司 2024-08-29 07:07:55

试试这个!

与上面的其他答案相同...

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

除了有效的神奇网址https://drive.google.com/uc?id=< ;docId>&embedded=true


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

  • https://drive.google.com/open?id= 共享链接。
  • https://docs.google.com/document//edit 在 Google 云端硬盘中打开。
  • https://docs.google.com/document/d//view 与上面的“编辑”相同。我认为。
  • https://docs.google.com/document/d//pub?embedded=true 对于嵌入 iframe,如果您 File ->发布到网络...
  • https://drive.google.com/uc?export=download&id= 直接下载链接。

经过一系列不同链接的试验和错误后,我偶然发现了这个解决方案。希望这有帮助!

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!

ぽ尐不点ル 2024-08-29 07:07:55

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

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.

琉璃梦幻 2024-08-29 07:07:55

以下对我有用:

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

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>
£噩梦荏苒 2024-08-29 07:07:55

花了一个小时,如下所示:

示例:

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

请注意,需要 encodeURIComponent

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文