13 Replies Latest reply on Mar 25, 2013 1:26 PM by JADarnell

    very short script that will not work

    JADarnell Level 1

      Hello everyone: 

       

      In an attempt to take some baby steps into using Javascript in Acrobat, I wrote the following folder-level script:

       

       

      main();

       

       

      function main()

      {

          debugger;

       

         

         var PDFDoc = app.openDoc("/c/Documents and Settings/johnd/Desktop/Drivel.pdf");

       

      //  and so on...

       

      I placed the Javascript file in the Javascripts folder under the Acrobat folder.  I then called up the Javascript debugger and began running it through its paces.  On the openDoc call I get the following error message in the console:

       

      RaiseError: Acrobat cannot open this file because a task is still active in Acrobat. Please return to Acrobat and end the task before opening this file.

      App.openDoc:9:Console undefined:Exec

      ===> Acrobat cannot open this file because a task is still active in Acrobat. Please return to Acrobat and end the task before opening this file.

       

      I am about at my wits end trying to figure out what task is running and why the script cannot open the document.  I am not running any other scripts and AFAIK Acrobat has completed all other processing.  So what do I need to do to fix this broken script?

       

      TIA!

       

      John

        • 1. Re: very short script that will not work
          Test Screen Name Most Valuable Participant

          Are you trying to open a file from the folder level scripts? Too early I suspect.

          • 2. Re: very short script that will not work
            JADarnell Level 1

            I am.

             

            However, upon figuring out that part of the problem might be that Acrobat is running the script as Acrobat is being loaded, I waited until Acrobat was done loading and then opened up the debugger and ran the script from the console.  I got the very same error.

             

            Are there any other approaches I should try?

             

            R,

            John

            • 3. Re: very short script that will not work
              Test Screen Name Most Valuable Participant

              Could it be that there is an embedded JavaScript in the file that is causing the problem? Does it happen with a different sample PDF?

               

              Also, try a different routine name in case main() has some significance.

              • 4. Re: very short script that will not work
                JADarnell Level 1

                That is something that I will check out, but my initial reaction  is no.  This is a very small file I made from an InDesign document I also created from scratch, so I am pretty certain of what is in it; just a bunch of text to be scanned.

                 

                I  will try your suggestion and get back to you post haste.

                 

                R,

                John

                • 5. Re: very short script that will not work
                  Test Screen Name Most Valuable Participant

                  Also, what does (or what is it hoped that) this line do:

                   

                  debugger;

                  • 6. Re: very short script that will not work
                    JADarnell Level 1

                    According to the documentation, if I place that command anywhere in a Javascript file and then run the Javascript, if the debugger is not up and running, it will cause the debugger to show.  It seems to work without a hitch, but if you think that it is interfering with the running of the script, I will remove it.

                    • 7. Re: very short script that will not work
                      Test Screen Name Most Valuable Participant

                      Thanks, found it now (I was looking for a class, not a keyword).

                      • 8. Re: very short script that will not work
                        gkaiseril MVP & Adobe Community Professional

                        Acrobat forms use JavaScript, not Java, not C#, etc.

                         

                        Are you truing to open the JavaScript console in an Acrobat field using an external computer language and manipulating the JSO?

                         

                        To show the console object from within an open PDF file use the following console methods:

                         

                        console.show(); // open the JavaScript console;

                        console.clear(); // clear the JavaScript console;

                        console.println("Hello World!"); // print a line to the console;

                         

                        console.hide(); // hide the JavaScript console;

                        • 9. Re: very short script that will not work
                          JADarnell Level 1

                          Okay, I changed the name of the main function to DoThis() and it made no difference.

                           

                          I created a brand new InDesign document with one single object; a text box filled with placeholder text.  I then exported that document to a PDF file, print type.  That made no difference.

                           

                          Just for the record I open up Acrobat and the script runs because it is a folder script  It errors out at the openDocument command with the same error reported before.

                           

                          So I close the debugger, wait a few moments, then reopen the debugger and set the view mode to Script and Console.  I then type in DoThis(); in the console box and press CTRL+Enter.  The script runs and crashes at the same place.

                           

                          R,

                          John

                          • 10. Re: very short script that will not work
                            gkaiseril MVP & Adobe Community Professional

                            If you want a folder JS for Acrobat, save the following code in an application level folder:

                             

                            function HelloWorld() {

                            console.show(); // open the console object;

                            console.clear(); // clear the console display;

                            console.println("Hello World!"); // print a line of text;

                            return true;

                            } // end HelloWorld funciton;

                             

                            With an open PDF file, open the JavaScript console and enter:

                             

                            HelloWorld();

                             

                            Highlight the text, and then use Ctrl + Keypad Enter Key.

                            • 11. Re: very short script that will not work
                              JADarnell Level 1

                              I am attempting to use Javascript and only Javascript.  The debugger command was tossed in early on when I was just starting to work with this script.  The debugger as invoked by CTRL-J was showing grayed-out debugging controls and adding the "debugger" command was my attempt to figure out why. 

                               

                              As I said in the very first post of this thread, I am just beginning to learn Javascript in Acrobat so I really do not know what I am doing, just yet.  It's a lot of "throw it on the wall to see if it sticks" operation.

                               

                              I later figured out that the folder script was being run at startup, but that it could be called again by placing the name of the main() function in the console window and pressing CTRL+Enter. (FYI, I am using a Windows box.)

                               

                              Please be patient with me; I am an experienced programmer, but in other languages like C, C++ and PHP.  I may have to unlearn some things before I am successful with Javascript in Acrobat.

                               

                              R,

                              John

                              • 12. Re: very short script that will not work
                                JADarnell Level 1

                                The eventual goal of this script is to open a PDF file, go through its text and look for certain words that are important to my company.  In the end we will actually be going through a folder of PDFs, one by one and execute the text screening routine.

                                 

                                As I said in my first post, this particular script was meant to be a baby step; to learn how to open a PDF up and do a quick search of some boilerplate text.  The more complex stuff would be added once I knew how to open up a PDF file.

                                 

                                R,

                                John

                                • 13. Re: very short script that will not work
                                  JADarnell Level 1

                                  Well, it turns out that you may be righter than all the rest.  I removed the debugger command and the document opened without error.  I still have some problems with this script, but I'll start a new discussion if I cannot figure out those problems on my own.

                                   

                                  Thanks to all who contributed.  Without you all offering suggestions I would not have finally come across the solution that works.

                                   

                                  R,

                                  John