11 Replies Latest reply on Jan 1, 2012 4:03 AM by Ken Krugh

    Javascript in batch sequence

    Ken Krugh Level 1

      I've done some Acrobat scripting but mostly through VB and I'm able to write what I need but I want to have it as part of my operator's Acrobat instead of the of separate program. That said, I want to write a Java script that I can include in batch sequence.

       

      I need to add a page to the start of a document and I want to have that page be nubered "a" without disturbing the numbering else where in the file. By simply adding the page at the start with the batch sequence it adopts the numbering of the first page. So if the first page is numbered as "i" then the new inserted page gets numbered "i" and the rest of the numbering changes, what was i becomes ii, what was ii becomes iii, and so on. I'm able to script this in VB by adding the page at the end, renumber them using the SetPageLabels from a Javascript object, then moving the page to the beginning.

       

      Is there any documentation on using Javascript within a batch sequence?

       

      Thanks,

      Ken

        • 1. Re: Javascript in batch sequence
          try67 MVP & Adobe Community Professional

          Have a look at the setPageLabels method of the Document object.

          1 person found this helpful
          • 2. Re: Javascript in batch sequence
            Ken Krugh Level 1

            Thanks try, yeah, I've used that in my VB progs.

             

            In VB I'm able to use a GetActiveDoc command which returns just that, the top-most Acrobat document Window. I've used the activeDocs in Java but activeDocs[0] appears to be the fist open document, no necesasry the top / active document.

             

            Do you  know if there is anything that can return the active document?

             

            Thanks again,

            Ken

            • 3. Re: Javascript in batch sequence
              try67 MVP & Adobe Community Professional

              In a batch process, the "this" object returns the document that is

              currently being processed.

              • 4. Re: Javascript in batch sequence
                Ken Krugh Level 1

                Yeah, I was hoping to be able to have them run with a batch sequence set to "Files Open in Acrobat" but then be able to use the Java code to process just one document. Kind of having my cake and eating it too.

                 

                It's looking more and more like using a separate program I already konw how to write in VB is the way to go.

                 

                Thanks for all your help!

                Ken

                • 5. Re: Javascript in batch sequence
                  try67 MVP & Adobe Community Professional

                  I don't really understand what you're trying to do, then... The entire

                  point of  batch sequence is being able to process multiple files in the

                  same way. If you only want to run the script on a single file, execute it

                  from the console or from a menu item. In both this cases, by the way, the

                  "this" object also points to the currently active document.

                  • 6. Re: Javascript in batch sequence
                    Ken Krugh Level 1

                    Well, I was trying to use the batch sequence because it is something my operators are familiar with. I looked up the consol a bit but I thing it'll be too clunky for some of my operators.

                     

                    What did you mean by executing it from a menu item?

                    • 7. Re: Javascript in batch sequence
                      try67 MVP & Adobe Community Professional

                      If you create a folder-level script (basically a .js file that you install

                      into the dedicated javascripts folder of Acrobat), it can add a new menu

                      item or toolbar item to the GUI to Acrobat, and you can assign a method to

                      it, so that that method is executed when the button is clicked.

                      1 person found this helpful
                      • 8. Re: Javascript in batch sequence
                        Ken Krugh Level 1

                        Didn't know that was possible, I'll definately check it out!

                         

                        Playing aroud with the console a bit, still haven't figured how this works, am pretty perplexed. Also having trouble with Acrobat blowing up.

                         

                        If I type code into the console window it isn't there when go back into Acrobat. I created a .js file in the correct folder and the script shows in the JacaScript Debugger but I can't figure out how to run or edit it!

                         

                        Oy

                        • 9. Re: Javascript in batch sequence
                          Ken Krugh Level 1

                          Well, hacking along here working in the console pasting my code in.

                           

                          The script adds a single page from another Acrobat file to the start of the open PDF. I need the page that goes in at the front to be numbered "a" and NOT effect numbering in the rest of the pages. Some files work fine, other files not so much, like the Javascript API reference PDF as well as other PDFs we've created here form InDesign.

                           

                          The script inserts a page at the end of the PDF and numbers that page "a" then moves it to the start of the document. The problem occurs when the page is moved to the start, it changes the number of all the other pages to follow page "a" which is a bit of a silly thing to have to send my clients. I decided to compromise and if the first page (before I insert the anything) was numeric I would simply try changing things to start page 1 after my inserted page "a".

                           

                          My code looks like this:

                           

                          var NumPages = this.numPages

                          var PgLabel = this.getPageLabel(0)

                          this.insertPages(NumPages-1, "/F/TNTSTUFF/Disclaimers/HUP_ProofNotice.pdf")

                          this.setPageLabels(NumPages,["a", "", 1]);

                          this.movePage(NumPages, -1)

                          if (PgLabel.match("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {  

                                  this.setPageLabels(1, ["1", "", 1]);  

                             }

                           

                          However, the setPageLabels command is causing this error:

                          RaiseError: The base pages object is missing or invalid.

                          Doc.setPageLabels:7:Console undefined:Exec

                          ===> The base pages object is missing or invalid.

                           

                          I'm not sure it is relavent, but on the files that work the numbering in Acrobat looks like this with the parentheical numbers:

                          Untitled-1.jpg

                          Files that DON'T work look like this, with NO parenthetical:

                          Untitled-2.jpg

                           

                          Even if I manually renumber the pages starting with 2 to make the numbering in the 2nd file look more like the numbering in the first file, I still get the error.

                           

                          Is there a way I can overcome this with Java code and what the heck is it?

                           

                          Thanks again to anyone who can help.

                           

                          Best,

                          Ken

                          • 10. Re: Javascript in batch sequence
                            try67 MVP & Adobe Community Professional

                            You're not specifying valid values in the aLabel parameter. The first value should be "D" if you want to use decimal numbering.

                            • 11. Re: Javascript in batch sequence
                              Ken Krugh Level 1

                              Yes, I found that, thatnks! Now I'm going to have a look at running it from a menu.

                               

                              Thanks again!

                              Ken