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

Script execution within JS Debugger Not Working For Scripts

New Here ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

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

Views

718

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

Copy link to clipboard

Copied

Does you execute the function? Any error message in the console?

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

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)

   }

}

Votes

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

Copy link to clipboard

Copied

You must execute the function with:

Split();

Votes

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

Copy link to clipboard

Copied

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?

Votes

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

Copy link to clipboard

Copied

Try it without the try-catch.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

Where does you save the script in the document?

Votes

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
Community Expert ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

LATEST

[Question moved to the JavaScript forum]

Votes

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