3 Replies Latest reply on May 21, 2010 3:46 PM by try67

    extractPages Crashes!!!

    caeriel

      Help!!
      The extractPages method is giving me fits!  I've been at this for days and am no closer to solving the problem than when it first happened!!

      Environment: 
           OS: WindowsXP (sp2)
           Acrobat 8.1xx professional

      Scenario:
      My users have a single multi-page pdf that needs to be broken up into single 2-page pdf documents.
      I've created a form in which they can enter the pertinent information:
            name of the pdf document to be processed
            location path of the pdf document to be processed
            the number of pages to be extracted for each new pdf document
            location path to dump the new pdf documents
      Once the form is completed they click the Process button and the following javascript is executed from the button mouse up:

      var lsMasterPath = this.getField("masterPathTxt").value;
      var lsMasterFileName = this.getField("masterFileNameTxt").value;
      var liNumPages = this.getField("extractNumPagesTxt").value;
      var lsStaticName = this.getField("staticNameTxt").value;
      var lsExtractedPath = this.getField("extractedPathTxt").value;

      var lsCSVDocName = "TX,AZ";
      var lsTempString = "";

      lsTempString = lsTempString + "Master Path: " + lsMasterPath + "\n";
      lsTempString = lsTempString + "Master File Name: " + lsMasterFileName + "\n";
      lsTempString = lsTempString + "Extract Number: " + liNumPages + "\n";
      lsTempString = lsTempString + "Boiler Plate Name: " + lsStaticName + "\n";
      lsTempString = lsTempString + "Extraction Path: " + lsExtractedPath + "\n";
      app.alert("In button:mouseup Javascript: \n" + lsTempString);

      extractMasterPages(lsMasterPath, lsMasterFileName, liNumPages, lsStaticName, lsExtractedPath, lsCSVDocName);


      The extractMasterPages function is a folder level trusted function saved in the Acrobat installation folder:
      C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Javascripts.

       

      extractMasterPages script:

      var extractMasterPages = app.trustedFunction( function(asMasterPath, asMasterFileName, aiExtractNumPages, asStaticName, asExtractedPath, asCSVDocName)
      {
               lsMasterPath = asMasterPath;
               lsMasterFileName = asMasterFileName;
               liNumPages = aiExtractNumPages;
               lsStaticName = asStaticName;
               lsExtractedPath = "/C/!Projects/Grants PDF Assistance/Separated Files/";
               lsDocNamesString = asCSVDocName;
                       
              ls_TempString = "";
              ls_TempString = ls_TempString + "Master Path: " + lsMasterPath + "\n";
              ls_TempString = ls_TempString + "Master File Name: " + lsMasterFileName + "\n";
              ls_TempString = ls_TempString + "Extract Number: " + liNumPages + "\n";
              ls_TempString = ls_TempString + "Boiler Plate Name: " + lsStaticName + "\n";
              ls_TempString = ls_TempString + "Extraction Path: " + lsExtractedPath + "\n";
              app.alert("In Trusted function: \n" + ls_TempString);
             
               ls_TempFileName = "";
               ls_ExtractedFileName = "";
               ls_NewFileName = "";
             
               li_Cntr = 0;
               li_TotalPages = 0;
             
              ls_TempFileName = lsMasterPath + lsMasterFileName;
               var myDoc = app.openDoc({cPath: ls_TempFileName, bHidden: true});
              li_TotalPages = myDoc.numPages;
              app.alert("Number of pages to process: " + li_TotalPages);
             
              for (li_Cntr = 0; li_Cntr < li_TotalPages; li_Cntr += 2)
              {
                  ls_ExtractedFileName = lsStaticName + "_" + li_Cntr + ".pdf";
                  ls_NewFileName = lsExtractedPath + ls_ExtractedFileName;
                  app.beginPriv();
                  myDoc.extractPages({nStart: li_Cntr, nEnd: li_Cntr + 1, cPath: ls_NewFileName});
                  app.endPriv();           
              }//<-- end for loop
      });

      You'll notice that I've placed several app.alerts at strategic places.  These alerts display the correct information that I'm expecting.
      The pdf document to be processed opens.... But when I get to the line:
                   myDoc.extractPages({nStart: li_Cntr, nEnd: li_Cntr + 1, cPath: ls_NewFileName});

      I get the following error message:
      Acrobat JavaScript Debugger Functions Version 7.0
      Acrobat Database Connectivity Built-in Functions Version 8.0
      Acrobat EScript Built-in Functions Version 8.0
      Acrobat Annotations / Collaboration Built-in Functions Version 8.0
      Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
      Acrobat Multimedia Version 8.0
      Acrobat SOAP 8.0
      Exception in line 55 of function anonymous, script Folder-Level:App:extract_Master_Pages.js
      Exception in line 17 of function top_level, script Field:Mouse Up

      NotAllowedError: Security settings prevent access to this property or method.
      Doc.extractPages:55:Field btnProcess:Mouse Up


      I'm new to Acrobat Javascript but not to javascript in general.  I've read the documentation until my eyes are crossed all to no avail. 
      According to the documentation and everything I've been able to dig up on the 'net extractPages has to run in a privileged environment and the way to create a privileged environment is to create a folder level trusted function.  I've done that and it still doesn't work! 
      I've even gone so far as to hard code in the safe path.  I've also made sure that both my form and the pdf to be processed have the Disclosed = true;  .

       

      What am I doing wrong??  Can anyone spot the problem??  As scripts go, it's not very big or complicated...  It can't be that difficult!!

       

      I'm at my wits' end....   Any help is greatly appreciated.

       

      caeriel

        • 1. Re: extractPages Crashes!!!
          try67 MVP & Adobe Community Professional

          Make sure the path you use doesn't contain any illegal characters, or a

          comma (which Acrobat considers to be not safe, for some reason). For

          example, I would try to remove the "!" from your path.

          • 2. Re: extractPages Crashes!!!
            caeriel Level 1

            Thank you.  You nailed it.  The exclamation point in the target path was causing the problem.  Once I removed it my little scrip worked like a charm.  I do have one other question:  if the exclamation point was causing the problem, why then, was I able to open the document in the same root folder?

             

            As I indicated I'm new to Acrobat Javascript but I'm experienced with the generic "real world" javascript.   I've looked in the documentation and I've only seen the specific Acrobat functionality referenced.  Does the Acrobat flavor of javascript support the normal functionality of javascript?  I'm looking to do some string processing and the "split" method as well as some of the other generic javascript string methods would really be handy.

             

             

            I can't believe I've spent days trudging through documentation, websites, etc. and it was a simple fix.....   (sigh....)

             

            Thanks again for your help.

             

            caeriel

            • 3. Re: extractPages Crashes!!!
              try67 MVP & Adobe Community Professional

              The reason is that Acrobat itself uses less strict rules than JavaScript in

              Acrobat. Odd, but that's the way it is.

               

              The answer to you other question is yes. Acrobat JS supports all generic JS

              functions, like split. Try it out and you will see that it works.