在网站上嵌入Google云端硬盘中的PDF文件 [英] Embed PDF File Hosted on Google Drive on Website

查看:537
本文介绍了在网站上嵌入Google云端硬盘中的PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经设置了oauth2并且可以成功登录用户。然后,他们可以输入一个文件ID,我的网站将返回该文件的所有元数据。



然而,我似乎无法嵌入此PDF文件。在元数据中有两个网址:
$ b


  • webContentLink

  • webViewLink



我试图用两个链接创建一个iFrame,但都没有成功。



这甚至有可能吗?

我使用JS来完成所有这些工作,并请求 https://www.googleapis.com/auth/drive.metadata.readonly 作用域。

解决方案

webContentLink

  https://drive.google.com/file/d/PDF_DRIVE_ID/view?usp=drivesdk 

嵌入网址

  https://drive.google.com/file/d/PDF_DRIVE_ID/preview 

现在,我还没有看到一个直接的API方法来获取 embedabb链接,但是如果您打算通过代码执行此操作,则只需操作 webContentLink ,以便删除视图?usp = drivesdk 部分,并用预览



示例片段替换它:

 < iframe src =https://drive.google.com/file/d/PDF_DRIVE_ID/previewwidth =640height =480> < / iframe中> 


There is a team drive full of PDFs.

I have set up oauth2 and can successfully login users. They can then enter in a file Id and my site will return all of the metadata for that file.

However I cannot seem to embed this PDF file. In the metadata there are two urls:

  • webContentLink
  • webViewLink

I tried creating an iFrame with both links but neither work.

Is this even possible to do?

I am using JS to do all of this and I am requesting the https://www.googleapis.com/auth/drive.metadata.readonly scope.

解决方案

webContentLink and the embeddable link have minor differences.

webContentLink:

https://drive.google.com/file/d/PDF_DRIVE_ID/view?usp=drivesdk

Embed URL:

https://drive.google.com/file/d/PDF_DRIVE_ID/preview

Right now, I haven't seen a direct API method to fetch the embedabble link but if you plan to do this by code, you can just manipulate the webContentLink so that it removes the view?usp=drivesdk part and replace it with preview.

Sample snippet:

<iframe src="https://drive.google.com/file/d/PDF_DRIVE_ID/preview" width="640" height="480"></iframe>

这篇关于在网站上嵌入Google云端硬盘中的PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆