0

I am trying to start learning Adobe JavaScript and use it in HTML. I downloaded the Acrobat JavaScript Scripting Guide and Reference to help me with the code but I don't know where to put that code. I wish it can be something I put in a web browser.

I don't think I can simply embed a pdf in my HTML and use JavaScript to refer to it because the manual says:

HTML JavaScript cannot access PDF elements, only Acrobat JavaScript can

(I am not sure though)

Now what should I do to use Acrobat JavaScript in HTML (how to include the code)?

Mostafa
  • 13
  • 2
  • 6
  • To clarify more, the purpose is to control any PDF doc in the browser. Not full control, only slight control such as scrolling, printing and highlighting some text. There is a start point in [Adob's manual](http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/reader_overview.pdf#page=26): _PDF browser controls interface enables you to treat a PDF document as an ActiveX_ and also _PDF browser controls are available through the AxAcroPDFLib.AxAcroPDF interface_ & gives methods to control the PDF such as `GoBackwardStack` `Print` from the browser. How can this **ActiveX** be accesses? – Mostafa Mar 16 '11 at 08:55
  • This question has not been answered, but I want the same answer. I want to be able to have records of files displayed -- one record at a time -- on the left side and have adobe acrobat embedded in say a div on the right side. When I change records, I want javascript to be able to tell Adobe to go to page X of the document (one PDF document will include multiple documents that the records will provide detail for). If you're still reading this, any answer? – thf Sep 29 '11 at 13:52

3 Answers3

1

JavaScript code requires a host application to execute. The host application has a JavaScript engine which will execute JavaScript code in documents that the host application is fed.

The JavaScript engine in a browser will execute JavaScript code in a web page. A

PDF viewer or plugin will execute Javascript code inside a PDF document.

The JavaScript code in a web page cannot interact with the JavaScript code in a PDF document and vice versa, as they are executed by different JavaScript engines.

BZ1
  • 1,306
  • 2
  • 8
  • 10
  • thanks a lot. This explains a lot. But still, how can the acrobat methods be **accessed** from `JavaScript` in a web browser? The manual mentions `PDF browser controls interface` through which the `PDF document` can be treated as `ActiveX`. It also mentions `AxAcroPDFLib.AxAcroPDF` to manipulate the PDF. But **how do I include it in JavaScript** (IE or FireFox)?? Simply typing `AxAcroPDFLib.AxAcroPDF` doesn't cause any results??! – Mostafa Mar 15 '11 at 07:54
  • The ActiveX interface provides JavaScript in the web page some control over the PDF plugin - the PDF viewer. However, I do not think the plugin ActiveX will expose the JavaScript in the PDF document to the JavaScript in the web page. If you need to embed JavaScript to manipulate PDF elements, you need software such as Adobe Acrobat or a PDF library. PDF libary are typically written in languages such as C, C++, Java or C#. Although there is a JavaScript library for generating PDF documents, it still does not allow interaction between Javascript code in web page and PDF documents. – BZ1 Mar 16 '11 at 05:14
  • Well, [the Manual](http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/reader_overview.pdf#page=26) says the ActiveX provides some properties and Methods to **slightly** control the Doc (not full control, but that's enough 4 me). It has a `AxAcroPDFLib.AxAcroPDF` interface which provides the properties and methods such as: `GoBackwardStack` `Print` `SetPageMode` etc. Just don't know how to access them :( – Mostafa Mar 16 '11 at 08:33
  • To program with ActiveX components, you need to use a language such as VB, VBA, C++, C#, Delphi, C++BUilder or something similar. – BZ1 Mar 22 '11 at 04:31
1

The execution environment for Acrobat JavaScript is within a PDF. Some PDF viewers other than Acrobat/Reader support this object model to some degree or another, but for the Real Deal, you need an Adobe PDF program.

You can download a free trial of Acrobat Pro from adobe.com, that'll get you started.

  1. Once you have Acrobat Pro, open up any old PDF, add a button to it (NOT with LiveCycle Designer),
  2. Edit that button's actions (last tab)
    I suggest you pick the mouse-up event (the default), though there are several others to choose from.
  3. You then select the action type "Run A JavaScript", you'll have to scroll down a bit.. and click "add"
  4. Type your JS into the resulting JS editing window. Their JS editor is Weak.
  5. Start typing.
  6. Close the editor, and close the button properties.
  7. click on the button (with the hand tool, like a normal user)
  8. Check the JS console for where you went wrong. ;) ctrl+j to bring it up.

You can also type script directly into the JS console and hit ctrl+enter to evaluate it, but this is really only useful for one-liners.

Your magic debugging function is console.println(). Note that the JS console actually supports things like setting break points, stepping through code, and so forth. All very handy.

A good script to start might be something as trivial as:

app.alert( "hello world" );

or

console.println( this );

You'll find that this is almost always the document object.

What are you trying to do with your PDF script?

PS: There actually IS a way to communicate between a web page and a PDF, but it's a little convoluted, and I've never actually seen anyone do it. Both the page and the PDF have to use specifically named functions that are called by The Other Environment.

Other handy code snippet:

// assuming 'this' is the "doc", which as I noted earlier, is generally the case
this.getField("fieldName").value

function whatAllDoesThisThingHave(thing) {
  console.println( thing );
  for(var i in thing) {
    console.println( "\t" + i + ": " + thing[i] );
  }
}

this.submitForm(url, bazillion, other, parameters, check, the, docs);

To access the PDF control, I think your best bet would be something I found here:
Recommended way to embed PDF in HTML?

Specifically:

<div id="pdf">
  <object width="400" height="500" type="application/pdf" data="/my_pdf.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">
    <p>Insert your error message here, if the PDF cannot be displayed.</p>
  </object>
</div>

I believe you can access the ActiveX control via getElementById("pdf_content"), though I could be mistaken. I'm a PDF Guy.

Community
  • 1
  • 1
Mark Storer
  • 15,672
  • 3
  • 42
  • 80
  • Thanks a million mark, that was very accurate & comprehensive. I followed your steps and it works gr8. However, I really need to put it in a web browser. The manual from Adobe says: "PDF browser controls interface **enables you to treat a PDF document as an ActiveX document** within an external application...possible to load a file, move to various pages within the file....**available through the AxAcroPDFLib.AxAcroPDF interface**": Not really gr8, but Works 4 me, cuz I only wanna **navigate** through a doc. But **how2 Access this ActiveX & methods:** `PrintAllFit` `SetShowToolbar` etc?? – Mostafa Mar 16 '11 at 08:01
  • If a PDF doc can be used as an `ActiveX` as the adobe manual says, maybe there is a simple way to do simple things inside the browser?? (because I can't put the code in all my PDF's - especially when I have to update the code, it would be very painful with a lot of PDFs) [link](http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/reader_overview.pdf#page=26) But how do I put that `ActiveX` inside the browser and access its properties/methods? – Mostafa Mar 16 '11 at 08:12
0

I seem to have found something from one of Adobe's manuals relevant to this question. It is not a total answer, but at least it can help.

On Windows, the only OLE automation supported for Adobe Reader is the PDF browser controls interface, which enables you to treat a PDF document as an ActiveX document within an external application. This makes it possible to load a file, move to various pages within the file, highlight a text selection, and specify various print and display options, as shown below.

If this helps to manipulate PDF from HTML JavaScript, the question is now:

how could I access PDF browser controls interface??

The manual says I should use, AxAcroPDFLib.AxAcroPDF this PDF browser controls but how should I access that??

I think all the puzzle pieces are on the table, I just don't know how to put them together!!

Mostafa
  • 13
  • 2
  • 6
  • It also says, which enables you to treat a PDF document as an `ActiveX` document. Does it help? How do we implement an `ActiveX` in `HTML`? – Mostafa Mar 15 '11 at 07:25