Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adobe Acrobat Pro XI - Adding Javascript to a PDF

This may seem like a really novice question, but I have been tearing my hair out all day on this.

I am running the trial version of Adobe Acrobat Professional XI I am looking to add simple JavaScript to a PDF file.

The aim is to have a PDF file, that when opened, pops up with an alert message with Yes and No options. Click Yes, and the alert goes away, leaving the PDF to be read. Click No, and the file closes.

The main trouble I am having is where to write my code. I have used the JavaScript Debugger but it is not very intuitive, and doesn't seem to let me add JavaScript to the file, only run from within the debugger.

All the tutorials I have looked at online show me the code, but not where to write it.

like image 468
Devan Somaia Avatar asked Jun 19 '14 13:06

Devan Somaia


People also ask

How do you add JavaScript in Adobe Acrobat Pro?

The JavaScript debugger in Acrobat lets you review your code line by line, set breakpoints, and inspect variables using the debugger dialog. To enable JavaScript Debugger, go to Edit > Preferences > JavaScript, and then select the Enable JavaScript debugger after Acrobat is restarted option.

How do I enable JavaScript in Adobe PDF?

Choose Edit > Preferences (Windows) or Acrobat / Acrobat Reader > Preferences (Mac OS). From the Categories on the left, select JavaScript.

Can PDF contain JavaScript?

NitroPDF and Adobe Acrobat definitely support JavaScript in PDF files.

Does Adobe support JavaScript?

Acrobat and Acrobat Reader let you adjust application behavior so that JavaScript executes within your desired level of security.


1 Answers

In Adobe Acrobat open Tools pane on the right, select JavaScript section and then Document JavaScripts.
Enter a script name and click Add. In the JavaScript editor remove the generated code and add yours:

app.alert({cMsg: "JavaScript action: hello", cTitle: "demo title"});

This code (if not placed in a function) will be executed automatically when the document is opened.

like image 151
iPDFdev Avatar answered Sep 30 '22 15:09

iPDFdev