3 Replies Latest reply on Sep 24, 2012 2:25 PM by jeanne_zzzzzzz Branched from an earlier discussion.

    Scripting help - page extraction

    jeanne_zzzzzzz Level 1

      I am trying to write a script where I extract various page ranges, insert a cover page, and apply a header.

      (document processing)

      I would prefer just to run the script.


      I cannot find much on the adobe site as how to run scripts, etc. Have read the SDK docs, but I am still lost.


      Need some tutorials.  Getting started, running simple scripts, etc.


      I have written extensive C,C++, VBA, etc. but writing the *.js on the fly.


      I cannot figure out how to execute it as a whole.


      I did run it in an Action, but it just bombed and I did not understand what the debugger said.

        • 1. Re: Scripting help - page extraction
          Test Screen Name Most Valuable Participant

          You can't just put a script in a *.js file and execute it with Acrobat scripts. Scripts may be

          - embedded in a PDF

          - run from the JavaScript console

          - run by external programs via API interfaces

          - in a file read by Acrobat at startup (definitions only)


          Also when you read the Javascript API, pay close attention to the security notes which usually limit or prevent exactly the things you most want to do.


          This sounds like something that is perhaps best done with OLE.


          If you don't understand what the debugger says, please give us the details! That is, copy and paste both script and error message, or take a screen shot.

          • 2. Re: Scripting help - page extraction
            George_Johnson MVP & Adobe Community Professional

            If this is the same script that you posted in an earlier thread, it would help if you added comments or otherwised explained exactly what you want it to do. It looks like you're making several mistakes that are easily fixable, but you need to provide more information. Once it's fixed, it can be run from the JavaScript console or in an Action.

            • 3. Re: Scripting help - page extraction
              jeanne_zzzzzzz Level 1

              I would have posted this earlier, but I cannot login to forums.adobe.com from home, although I can see it.  Odd.



              I put the new script in an action and it does the following:

              1.  The file I am extracting from is open when the Action starts. From the file that is open (referred to as "this" in my new script), the fm or front matter page is extracted and saved as.


                 str_file_fm = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_fm.pdf";

              2.  Other Page ranges are extracted, and saved in files


                 str_file[0] to str_file[4]


              3.  Through a for loop and function, each file is opened in succession.  str_file_fm is inserted as the cover page to each str_file[i] and an individual header (files  str_header[0]  to str_header[4] ) is added.  Looping i from 0 to 4, str_header[i] is added as the header to str_file[i].


              4.  It works good, but at the end all files are open and I have to save them manually. I would like to fix that.  It looks like I have to save each original file with a different name, then save the final draft as the filename I want. I would still have to delete the unwanted files manually in explorer, unless I can determine the syntax to delete a file that is not open.


              So, now my question is  "what is the syntax or keyword to delete a file that is not open???"  I cannot find anything in the Adobe API javascript document.


              Thank you for all your comments. I have been doing this task manually and with the original script you saw for a year.  I am now more knowledgable about javascript for Acrobat, even though I have just scratched the surface.



              The code I finally arrived at is.....




              /* inst241_sec2 */



              function  process_file(str_newfile,str_header,str_fm_page)


                  var oDoc = app.openDoc({ cPath: str_newfile });

                  console.println('"The file name of this document is '+ oDoc.documentFileName +'."');

                  oDoc.insertPages ({

                      nPage: -1,

                      cPath: str_fm_page,

                      nStart: 0



                      cText: str_header,

                      nFontSize: 7,

                      nTextAlign: app.constants.align.right,

                      nHorizAlign: app.constants.align.right,

                      nVertAlign: app.constants.align.top,

                      nHorizValue: -72, nVertValue: -22





              var str_file_fm = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_fm.pdf";

              var str_file = new Array(5);

              var str_header = new Array(5);


              str_file[0] = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_day1.pdf";

              str_file[1] = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_day2.pdf";

              str_file[2] = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_day3.pdf";

              str_file[3] = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_day4.pdf";

              str_file[4] = "/btc-nas1/jyoung/_24X_fall_2012/pdf/INST241_sec2/INST241_sec2_feedback.pdf";


              str_header[0] = "INST241_sec2_day1    Q 1 - 10";

              str_header[1] = "INST241_sec2_day2    Q 21 - 30";

              str_header[2] = "INST241_sec2_day3    Q 41 - 50";

              str_header[3] = "INST241_sec2_day4    Q 61 - 71";

              str_header[4] = "INST241_sec2_feedback    Q 81 - 90";










              for (var i = 0; i < 5; i++)








              Thank you --  jeanne_zzzzzzz