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.
- Once you have Acrobat Pro, open up any old PDF, add a button to it (NOT with LiveCycle Designer),
- 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.
- You then select the action type "Run A JavaScript", you'll have to scroll down a bit.. and click "add"
- Type your JS into the resulting JS editing window. Their JS editor is Weak.
- Start typing.
- Close the editor, and close the button properties.
- click on the button (with the hand tool, like a normal user)
- 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.