4

I want a frame with a PDF document. The main document will use javascript to tell the PDF document what page to display and zoom level. Can this be done? If so, how or could you point me to documentation on it. Thanks.

5 Answers 5

2

You can't/shouldn't do it in a frame, but you can create an <object> on your page that is controllable using the JavaScript API.

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

Sign up to request clarification or add additional context in comments.

2 Comments

This looks like not only what I need, but a lot more. Thanks! One problem -- how exactly do I refer to the document from script in the web page that has the object and then use the javascript described in adobe's api to manipulate it. Could you give a simple example.
I really want to check this as the answer, but I still need the answer to how to control it.
2

Not easily. It all depends on what's being used to display the PDF in the browser. Not all browsers have built-in PDF viewers, and then there's many different external viewers (e.g. Acrobat, Fox-It, etc...) as well. As far as I know, there's

You can try hacking up the URL like this:

http://example.com/somedocument.pdf#page=5

but this may work in Acrobat only, as documented here: http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf

1 Comment

At least the page parameter works with most PDF plugins I've seen so far.
2

Do you need a PDF reader to be loaded and running? If not, you could write a back end script/program to render a specified page as an image (GIF, PNG, etc.) at a particular zoom level. Then your main page could load an image with something like:

<img src="render_pdf?page=4&zoom=150">

The src value could be controlled with javascript to make it dynamic.

To convert from PDF to an image in your render_pdf script, you can use ghostscript, or an image specific library like ImageMagick or GD, depending on what backend technology you are using.

Comments

0

Have a look at jsPDF - it may not output a .pdf onscreen in IE6 and IE7 due to limitations with datauri's, but its a good start. I dont see why this couldnt be built up in an iframe either.

Comments

0

As Jordan pointed out, you should use the <object> tag to embed the PDF. Then, in the PDF itself, you need to embed Javascript to handle the messages you pass in, such as:

if(!this.hostContainer.messageHandler) this.hostContainer.messageHandler = new Object();
this.hostContainer.messageHandler.onMessage = handleMessage;
function handleMessage(msg) {
    // do stuff here
}

Finally, in your HTML JS, you pass messages in with:

document.getElementById('yourpdfobject').postMessage('some message or array');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.