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

Script execution within JS Debugger Not Working For Scripts

New Here ,
Jul 09, 2019 Jul 09, 2019

So, I am trying to figure out how to get code to run within the console. It seems like for simple things like 1+2 it works but any functions I have written as a document JS does not work. What am I missing?

For reference, I am splitting some files...

function Split() {

   var totalPages;

   var i;

   var arrNames = [ "SOME ARRAY HERE" ];

   var targetPath  = "/C/Users/SOMEPATH/";

   totalPages = this.numPages;

   try { for (i = 0; i  < totalPages; i++)

         this.extractPages({

            nStart: i,

            cPath: targetPath +arrNames + ".pdf"

         });

        console.println(targetPath +arrNames + ".pdf");

   } catch (e) {

       console.println("Aborted: " + e)

   }

}

TOPICS
Acrobat SDK and JavaScript
1.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 ,
Jul 09, 2019 Jul 09, 2019

Does you execute the function? Any error message 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 ,
Jul 09, 2019 Jul 09, 2019

Yes, I typed Split in console to execute but it actually returned the actual code for the function, which is super duper confusing. None of the console.println showed properly at all.

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 ,
Jul 09, 2019 Jul 09, 2019

Like, when I say actual code, I meant it literally.

i.e. I typed:

Split

Then this appeared below:

function Split() {

   var totalPages;

   var i;

   var arrNames = [ "SOME ARRAY HERE" ];

   var targetPath  = "/C/Users/SOMEPATH/";

   totalPages = this.numPages;

   try { for (i = 0; i  < totalPages; i++)

         this.extractPages({

            nStart: i,

            cPath: targetPath +arrNames + ".pdf"

         });

        console.println(targetPath +arrNames + ".pdf");

   } catch (e) {

       console.println("Aborted: " + e)

   }

}

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 ,
Jul 09, 2019 Jul 09, 2019

You must execute the function with:

Split();

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 ,
Jul 09, 2019 Jul 09, 2019

So, I tried it and yes, it no longer spit out the entire function. Yay!

But it didn't generate any of the lines that console.println() is supposed to either. Any suggestions?

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 ,
Jul 09, 2019 Jul 09, 2019

Try it without the try-catch.

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
LEGEND ,
Jul 10, 2019 Jul 10, 2019

1. I take it that your actual code did not include, literally, SOMEPATH....? Sorry if it's too obvious a point.

2. Question: Did running Split() produce any messages at all (expected or not)?

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 ,
Jul 10, 2019 Jul 10, 2019

Yea. I wrote the code so, no, SOMEPATH isn't there. It's a real path...

Split did not produce any messages at all. Zero. But I actually got it to work by copying the whole document JS into the console, and highlighted the code block and do a Ctrl+Enter. But that seems, purpose defeating? I mean, why have document JS included with the document when the code cannot be called from console??? How would you debug things otherwise??

And FYI, I copied the code from the API directly for the most part, but it apparently missed a curly bracket, added now below:

function Split() {

   var totalPages = this.numPages;

   var i;

   var arrNames = [ "SOME ARRAY HERE" ];

   var targetPath  = "/C/Users/SOMEPATH/";

   try {

      for (i = 0; i  < totalPages; i++) {

         this.extractPages({

            nStart: i,

            cPath: targetPath +arrNames + ".pdf"

         });

         console.println(targetPath +arrNames + ".pdf");

     }

   } catch (e) {

       console.println("Aborted: " + e)

   }

}

Like (0) •

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 ,
Jul 10, 2019 Jul 10, 2019

Where does you save the script in 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
Community Expert ,
Jul 17, 2019 Jul 17, 2019
LATEST

[Question moved to the JavaScript forum]

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