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

OpenDoc with array of filenames

New Here ,
Apr 16, 2017 Apr 16, 2017

I am trying to create a function that opens PDFs using an array with the filenames :

         var listDocs = ["KOOS.pdf", "OKS.pdf"]

        var arrayLength = listDocs.length;

        for (var i = 0; i < arrayLength; i++) {

              var otherDoc = app.openDoc(listDocs, this);

              otherDoc.getField("Serial").value=otherDoc.getField("Serial").value+1;

              var pp = otherDoc.getPrintParams();

              otherDoc.print(pp);

              }

I am getting the error

NotAllowedError: Security settings prevent access to this property or method

It works if I just have a variable :

var listDocs = "KOOS.pdf"

and don't use the loop. It also works if I have an array with only one filename in it.

Thanks for your help

TOPICS
Acrobat SDK and JavaScript
373
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

correct answers 1 Correct answer

Community Expert , Apr 17, 2017 Apr 17, 2017

1. Change this line:

var otherDoc = app.openDoc(listDocs, this);

To:

var otherDoc = app.openDoc(listDocs, this);

Also, you should not be using the "this" keyword as it might change to point to the current file you're opening in your loop.

Instead, create a variable that points to the original file at the start of your code and use it instead of "this".

So add this line at the top:

var oldDoc = this;

And then replace all instances of "this" with "oldDoc".

And you might want to add a command that closes th

...
Translate
Community Expert ,
Apr 17, 2017 Apr 17, 2017

1. Change this line:

var otherDoc = app.openDoc(listDocs, this);

To:

var otherDoc = app.openDoc(listDocs, this);

Also, you should not be using the "this" keyword as it might change to point to the current file you're opening in your loop.

Instead, create a variable that points to the original file at the start of your code and use it instead of "this".

So add this line at the top:

var oldDoc = this;

And then replace all instances of "this" with "oldDoc".

And you might want to add a command that closes the file after printing it.

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 ,
Apr 17, 2017 Apr 17, 2017
LATEST

Fantatsic. Thanks try67

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