Skip to main content
2Charlie
Inspiring
December 22, 2021
Answered

Why do I keep getting undefined in Acrobat Javascript console?

  • December 22, 2021
  • 3 replies
  • 4491 views

Here's a simple Javascript for-loop in Acrobat console. It works in any other console except Acrobat.

Any idea why?

 

I have also tried the following and still get undefined.

for(let i = 0; i < 10; i++){
 console.log(i);
};

 

This topic has been closed for replies.
Correct answer try67

Did you select the full code before executing it?

3 replies

try67
Community Expert
Community Expert
December 22, 2021

Just to add to the correct replies made above: "undefined" is not an error. The opposite, actually. It just means the code finished executing correctly, without throwing any errors or returning any values.

The issues with your code cause it to not actually do anything, but it is running.

ls_rbls
Community Expert
Community Expert
December 22, 2021

++ Adding to the discussion,

 

Would you mind describing what where you trying to achieve and why are you trying to declare a variable using "let"?

 

After much reading, I am almost convinced that you can't declare variables using "let" with  Acrobat JavaScript.

 

As illustrated by NesaNurani, when you script with an Acrobat PDF you must use "var" to declare variables. In addition, if you also write the same line of code and omit "var" when you express the for-loop function (shown in the example below), Acrobat JavaScript will automatically assume the variable declaration for the "i" indicator:


for( i = 0; i < 10; i++){
console.println(i);
};


In both instances (NesaNurani's correct example and the example illustrated above), the "i" indicator is initialized  as a global variable inside of the document that you're working with. Both examples will execute the same results.

 

Seems to me like you were testing this script to work around something in Acrobat like a server-side script to test with web browsers, for example (in which case is not directly supported in Acrobat).

See if these additional discussions are relevant:

 


As for "console.log", which is used to write or display data to the browser console, the standard output in Acrobat JavaScript is expressed with "console.println" instead. Otherwise, if successful, the Acrobat program will produce the write operation of the data transfer silently.

2Charlie
2CharlieAuthor
Inspiring
December 23, 2021

Here's the error I got.

I'm testing the script to rename all the field names in the PDF I have opened. At this point, I'm not even getting anything from the currently open PDF yet and it's giving me this error or undefined value. I have like 100 duplicate checkbox names that I want to make it unique.

 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 23, 2021

Did you select the full code before executing it?

Nesa Nurani
Community Expert
Community Expert
December 22, 2021

Use 'var' instead of 'let' and use 'println' instead of 'log'.

for(var i = 0; i < 10; i++){
console.println(i);
};