如何在Google的文档查看器中打开特定页面 [英] how to open specific page on Google's docs viewer

查看:137
本文介绍了如何在Google的文档查看器中打开特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google的文档查看器在html页面中显示pdf文档,并且我想从第20页而不是第1页开始打开该文档.

几乎没有关于Google的文档查看器服务的文档.他们在其网页 https://docs.google.com/viewer 中说,该服务仅接受两个参数(网址和嵌入网址),但我在网上搜索过其他参数,例如"a","pagenumber","v"和"attiet",但它们都对我没有作用.我尝试在网址末尾添加#:0.page.19(这是div的ID,该div包含Google创建的正文中的第20页),但是它只是忽略了它或以随机方式起作用.

你们知道如何告诉Google文档查看器从特定页面开始显示文档吗?

解决方案

我找到了一个解决方案,以防万一有人遇到同样的情况.

google的文档查看器iframe中的每个页面都有一个ID,例如:0.page.X,是页面编号的X.像这样调用服务

<iframe id="iframe1" src="http://docs.google.com/gview?url=http://yourpdf&embedded=true#:0.page.20">

不起作用(可能是因为在呈现页面时尚未创建页面ID?)

因此,您只需向iframe添加onload属性即可:

<iframe id="iframe1" src="http://docs.google.com/gview?url=http://yourpdf&embedded=true" onload="javascript:this.contentWindow.location.hash=':0.page.20';">

然后打开,加载后iframe将自动向下滚动.

请注意,页面索引是从零开始的.如果要在查看器中查看文档的第20页,则需要使用参数:0.page.19

I'm using google's docs viewer to show a pdf document in a html page and I would like to open the document starting on page 20 instead of 1 for example.

There's hardly any documentation about Google's docs viewer service. They say in its webpage https://docs.google.com/viewer that the service only accepts two parameters (url and embedded) but I've seen other parameters searching the web, like "a", "pagenumber", "v" and "attid", none of them did anything to me. I've tried to add #:0.page.19 at the end of my url (that's the id of the div containing page number 20 inside the body google creates) but it just ignores it or works in a random way.

Do you guys know how to tell google docs viewer to show the document starting on a specific page?

解决方案

I found a solution I'll post here just in case somebody is in the same situation.

Every page inside google's docs viewer iframe has an id like :0.page.X, being X the number of the page. Calling the service like this

<iframe id="iframe1" src="http://docs.google.com/gview?url=http://yourpdf&embedded=true#:0.page.20">

won't work (maybe because the pages ids are not yet created when the page is rendered?)

So you just have to add an onload attribute to the iframe:

<iframe id="iframe1" src="http://docs.google.com/gview?url=http://yourpdf&embedded=true" onload="javascript:this.contentWindow.location.hash=':0.page.20';">

and voilà, the iframe will automatically scroll down after loading.

Note that page indices are zero-based. If you want to view the 20th page of a document in the viewer, you would need use the parameter :0.page.19

这篇关于如何在Google的文档查看器中打开特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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