Copy link to clipboard
Copied
Creating a global variable when writing JavaScript in a file is is straight forward and obvious, but not when trying to set it in Acrobat via the Use JavaScript tool in Acrobat. I have read:
It is obvious that the Document javascripts strings tool is the place to enter JavaScript functions, as many as required can be added and are visible using the All javascript strings tool:
//<Document-Level>
//<ACRO_source>foo</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:foo ***********/
function foo()
{
console.println("Hello, world!");
}
//</ACRO_script>
//</Document-Level>
The added function is shown in the Scripts pane of the Javascript Debugger window indicating that Acrobat sees them.
However, it isn't obvious how to create a document global variable. When I add them manually to the All javascripts strings/Javascript Editor and close, the variable is lost as in it is not there when the Editor is opened again. As the functions are enclosed in <ACRO></ACRO> tags, it may that there are tags for the document level variables? If so, what are they? I assume that when a document level variable is created, it will be displayed in the Inspect pane of the JavaScript Debugger window because Variable/Value are shown in the header.
Copy link to clipboard
Copied
Just declare the variable in a doc level script
For example:
var a = "A";
That's all there is to it, simple 🙂
And as suggested by Try67, Don't use "Edit all scripts"
Copy link to clipboard
Copied
Do NOT edit the code via the All Javascripts command. You can seriously mess up your file doing that.
Use the Document JavaScripts command, instead, and place your code outside of a function. That way it will execute when the file is opened.
Copy link to clipboard
Copied
Just declare the variable in a doc level script
For example:
var a = "A";
That's all there is to it, simple 🙂
And as suggested by Try67, Don't use "Edit all scripts"
Copy link to clipboard
Copied
[MOVED TO THE ACROBAT DISCUSSIONS]