how to open specific page on Google's docs viewer

Juan picture Juan · Feb 8, 2012 · Viewed 41k times · Source

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?

Answer

Juan picture Juan · Feb 10, 2012

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