4 Replies Latest reply on Mar 17, 2011 3:02 AM by pkahrel-aIwdUo

    [JS][CS4]PDF Export With RegExp Doesn't Include First Zero-Please Help

    Danny Noonan Level 1

      This is a script we put together with the help of Jongware, Shonkyin and Kaysan a while back...

      Here's the link to the original thread:

      http://forums.adobe.com/thread/481958?tstart=0

       

      ( function() {

       

      if(app.documents.length != 0){

      var myFolder = app.activeDocument.filePath;

      if(myFolder != null){

      var myPageName, myFilePath, myFile;

      var myDocument = app.activeDocument;

           //var myBaseName = myDocumentName + "_" ;

      }     

           

                //1.  Update modified links, find and alert operator of missing links.

                var linksLog = updateLinks(myDocument, "");

           if (linksLog != "") {

                alert("Missing Links\n" + linksLog + "\nPlease resolve and try again.");

                return;

           }     

           

           function updateLinks(doc, log) {

                var myLinks = doc.links;

                for (var j = myLinks.length - 1; j >= 0; j--) {

                     switch (myLinks[j].status) {

                          case LinkStatus.normal :; case LinkStatus.linkEmbedded : break; // nothing to do

                          case LinkStatus.linkOutOfDate : myLinks[j].update(); break; // update

                          case LinkStatus.linkMissing :

                               log = log + "Link '" + myLinks[j].name + "' is missing\n";

                          break

                     } // end switch

                } // end for

                return log

           } // end updateLinks

       

       

      var my_suffix = decodeURI(app.activeDocument.name).replace(/^(\d+).*/, '$1');

      //my_suffix = Number(my_suffix);

      if (typeof (my_suffix) != 'number')

      {

      my_suffix = Number(my_suffix);

      }

      for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){

          if (myDocument.pages.item(myCounter).appliedSection.name != ""){

              myDocument.pages.item(myCounter).appliedSection.name = "";

          }

      myPageName = myDocument.pages.item(myCounter).name;

       

      app.pdfExportPreferences.pageRange = myPageName;

      myFilePath = myFolder + "/" + "MyTest_" + (my_suffix + myCounter) + ".pdf";

      myFile = new File(myFilePath);

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

      myDocument.exportFile(ExportFormat.pdfType, myFile, false, "[Press Quality]");

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

      }

          }

       

          else{

              alert("No documents are open. Please open a document and try again.");

              exit();

          }

       

      alert("Finished exporting");

       

      }())

       

      The problem is, I never considered pages 0 through 99. The script works perfect for 138-140 TEST 10_WORKER.indd. It creates PDFs named:

      MyTest_138.pdf

      MyTest_139.pd

      MyTest_140.pdf

       

      If the document name is 098-100 TEST 10_WORKER.indd, It creates PDFs named:

       

       

      MyTest_98.pdf -  should be MyTest_098.pdf 

      MyTest_99.pdf -  should be MyTest_099.pdf 

      MyTest_100.pdf - This is perferct

       

       

      And of course, the double 0s, 008-010 TEST 10_WORKER.indd

       

      MyTest_8.pdf -  should be MyTest_008.pdf 

      MyTest_9.pdf -  should be MyTest_009.pdf 

      MyTest_10.pdf -  should be MyTest_010.pdf 

       

      Why doesn't it use the first 0(s) in the name? 0 is a digit and every RegEx tester I've checked it with includes the zero.

       

      Any assistance with getting this script to use the leading zero if there is one would be greatly appreciated.

       

      Also, if there is a way to export each PDF from a multipage document which doesn't start with a number, it would be extremely helpful.

       

      Thanks in advance

       

      Danny