Skip to main content
Participating Frequently
June 4, 2021
Question

InvalidDocumentError when using Action Wizard

  • June 4, 2021
  • 2 replies
  • 2531 views

I am trying to run a date stamp script through action wizard, which works when run on a single file through the console. The script is

for (var p = 0; p < this.numPages; p++) {var f = this.addField("Date", "text", p, [350, 770, 600, 790] ); f.value = "Document Received: " + util.printd("mm/dd/yy hh:MM:sstt", new Date());}

When run I get the error InvalidDocumentError: Method called on invalid document objec: document.addField().

Thanks for the help!

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
June 8, 2021

Acrobat is having a problem with the "this" keyword. In most cases "this" is a pointer to the current document, which in a batch process is supposed to be the document currently being processes. However there's definately a problem with "this". It's saying the document is invalid. This usually happens when using a doc object after the actual document is closed. 

 

The real pointer to the current object in  batch process is "event.target", try replacing "this" with "event.target"

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
June 4, 2021

Before for loop add this lines:

  console.show();

  console.println(this.path);

 

Then you can see where the action stops.

Participating Frequently
June 4, 2021

I added the lines and ran it and it output 4: which I assume means the script failed on the fourth line which is var f = this.addField("NextPage", "text", p, [350, 770, 600, 790] ); I believe it is an issue with the this.addField, but this is my first time using javascript and I am unfamiliar with how this interacts.

Bernd Alheit
Community Expert
Community Expert
June 4, 2021

Check the document where it stops.