Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How/where to declare a document level global variable in Acrobat?

Community Beginner ,
Jan 24, 2025 Jan 24, 2025

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.

389
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 24, 2025 Jan 24, 2025

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"

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2025 Jan 24, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2025 Jan 24, 2025

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"

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025
LATEST

[MOVED TO THE ACROBAT DISCUSSIONS]


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines