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

InvalidDocumentError when using Action Wizard

New Here ,
Jun 04, 2021 Jun 04, 2021

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!

TOPICS
JavaScript
2.4K
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 ,
Jun 04, 2021 Jun 04, 2021

Before for loop add this lines:

  console.show();

  console.println(this.path);

 

Then you can see where the action stops.

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
New Here ,
Jun 04, 2021 Jun 04, 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.

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 ,
Jun 04, 2021 Jun 04, 2021

Check the document where it stops.

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
New Here ,
Jun 04, 2021 Jun 04, 2021

It stops at the first document

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 ,
Jun 04, 2021 Jun 04, 2021

Run the script in the console.

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
New Here ,
Jun 04, 2021 Jun 04, 2021

It works fine in the console, which is why I am confused when it fails when doing multiple files.

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 ,
Jun 04, 2021 Jun 04, 2021

Can you share the document?

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
New Here ,
Jun 04, 2021 Jun 04, 2021

The documents I am working with have sensitive data, but it fails with this sample pdf.

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 ,
Jun 04, 2021 Jun 04, 2021

Works fine for me. What other commands did you add to the Action?

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 ,
Jun 04, 2021 Jun 04, 2021

No problem with this file.

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
New Here ,
Jun 04, 2021 Jun 04, 2021

That's the only action I'm performing.

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
New Here ,
Jun 04, 2021 Jun 04, 2021

Well, thanks for the help, I thought there was an issue with the code that I did not understand, but now I know the code is all right, it seems to be an issue with the version I'm running.

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 ,
Jun 04, 2021 Jun 04, 2021

Repair the Acrobat Installation.

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 ,
Jun 04, 2021 Jun 04, 2021

Well, you should at least add a command to save the file after executing the JS code...

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 ,
Jun 08, 2021 Jun 08, 2021
LATEST

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 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