These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Open PDF from HTML page with javascript

ill_comms
Registered: Jul 26 2008
Posts: 3

Hi,

I have an intranet site that I'm building and some pages have links to various documents on the local machine, for PDFs I'd like to be able to load the Adobe Reader application then display the PDF external from IE with javascript.

I'm running it off XP, IE, Adobe Reader 8.

The following code is the javascript I use when I click from document link. It loads Adobe Reader then produces the error "There was an error opening the document. This file cannot be found".

I'm trying to find a way to define the document path to load.
If some one can give me some pointers I would greatly appreciate it!

try
{
control_text = "AcroExch.PDDoc";
control = new ActiveXObject(control_text);
pdfDoc = control.Open("C:\documents\trial.pdf")
//It loads Accrobat here but fails to to find document.
}
catch (e)
{
alert("Fail on load.");
}

My Product Information:
Reader 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The problem with this code is that it is running in HTML in the browser. The browser client does not see the local file system the way a regular desktop application does. You know, security. The file has to be loaded from an interenet URL. You're easiest solution is to run a web server for your intranet and load the file from there using a regular URL. If you want to load the file from a local hard drive or a mounted drive you'll need to use a "file" URL and adjust the IE security features to allow file access from a web page.

The correct WebPage method for loading a file is demonstrated on this page:

http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm

Look at the source for the top frame. There is also a simple example in the Acrobat 8 SDK, which you can download from here:

http://www.adobe.com/devnet/acrobat/


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script