Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


InvalidDocumentError when using Action Wizard

New Here ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

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

Views

566

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Before for loop add this lines:

  console.show();

  console.println(this.path);

 

Then you can see where the action stops.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Check the document where it stops.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

It stops at the first document

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Run the script in the console.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Can you share the document?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

No problem with this file.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

That's the only action I'm performing.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Repair the Acrobat Installation.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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