Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded PDF - open page number without reloading the document

Tags:

javascript

pdf

I have embedded a PDF document using the html object tag, and displayed it on one section of the webpage. Another section contains a tree-view of links (looks like the PDF's bookmarks). Clicking on a link in the tree-view reloads the PDF document and opens it on the correct page (page number is contained in the links). Is there a way to accomplish this without reloading the document?

To rephrase the question, I am looking for a JavaScript function that could imitate the behavior of the bookmarks - jumping to the page number without reloading the document.

like image 397
Donna Navales Petrick Avatar asked Nov 22 '12 21:11

Donna Navales Petrick


People also ask

How do you make the first page of a PDF display by itself and the succeeding pages display two up?

In Acrobat open the PDF document properties (Ctrl+D) and in the Initial view tab select Page Layout: Two-Up (Cover page). Then press OK and Save the file. That's it!

How do I open an embedded PDF in a new tab?

In Chrome, Ctrl + Shift + click opens a link in a new tab from a PDF (Windows). You can also right click and select 'Open link in new tab'.

Do embedded files open in a PDF?

Yes, you can open the embedded attachments in the Adobe Acrobat Reader mobile application. Please refer to the steps provided below to open the attachments on the Android device. - Open the PDF with attachments in the Adobe Acrobat Reader. - Then click on the three dots provided at the top right of the screen.


1 Answers

I think there is no native method in JavaScript that would provide that functionality. You are going to need a library.

The easiest way would be to use a well documented library to work with pdf documents in JavaScript. PDF.js is a very good project in that sense, although it renders the pdf itself, instead of using Acrobat Reader, which might give problems with complicated documents.


Another solution, using Adobe Acrobat reader, would be to use their own JavaScript API, following that link you will see the complete API reference. Quoting from that document (Page 254):

pageNum

Gets or sets the current page of the document. When setting pageNum to a specific page, remember that the values are 0-based. [...]

So if you wanted to go to a specific page of the document you could use

this.pageNum = 6;

Where this should be the app context. Here you can find the online API reference with more documentation and examples.

Some guides on using the above JS API:

  • http://blogs.adobe.com/pdfdevjunkie/web_designers_guide
  • http://cookbooks.adobe.com/post_Passing_information_actions_from_the_browser_to_an-18885.html
  • http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters_v9.pdf#page=5
like image 182
aurbano Avatar answered Oct 03 '22 03:10

aurbano