5 Replies Latest reply on Nov 30, 2018 8:52 PM by Manan Joshi

    how to truncate the file name in this script

    @Js1212 Level 1

      I found this "oldie but goodie" script and it is performing very well except the name of the PDF it produces includes the .indd

       

      for example Test.indd will create a PDF named Test.indd.pdf

       

       

       

      how do i rework this so it will produce a name like Test.pdf

       

      thank you

      scott

       

       

       

       

      //ExportPDF_in_Foreground.jsx 

      //Uwe Laubender 

      /**

      * @@@BUILDINFO@@@ ExportPDF_in_Foreground.jsx !Version! Wed Jun 23 2010 17:08:10 GMT+0200

      */ 

      //DESCRIPTION:PDF-Export in foreground (old school like in InDesign CS4) 

       

      if(app.documents.length>0){ 

          var d=app.activeDocument; 

          }; 

      else{ 

          alert("Please open a document to execute export to pdf. Script will be aborted."); 

          exit(); 

          } 

      if(d.saved == false){ 

          alert("Save your document first before executing export to pdf. Script will be aborted."); 

          exit(); 

          }; 

       

      var pdfPath = Folder.selectDialog("Folder to save LOW RES pdf:"); 

      var pdfName = d.name+"_LOW.pdf"; 

       

      var userDefFileName = prompt("File name:",pdfName,undefined); 

       

      if(userDefFileName == null){ 

          exit(); 

          }; 

       

      var pdfFullName = pdfPath+"/"+userDefFileName; 

       

      if(File(pdfFullName).exists){ 

          c=confirm("The PDF-file \""+userDefFileName+"\" is already existing. Do you want to overwrite it?",true,undefined); 

          if (c==0){exit()};   

          }; 

      //Error-handling if PDF file override is on and PDF is already opened in an PDF reader app: 

      try{ 

      d.exportFile(ExportFormat.PDF_TYPE,File(pdfFullName),true,undefined,undefined); 

      }catch(e){ 

          alert("Error:\r"+e.message+"\r\r(Line "+ e.line+" in script code.)"); 

          exit(); 

          };   

        • 1. Re: how to truncate the file name in this script
          Sudha K Level 1

          Hi,

           

               Replace ".indd" to "" or get substring from the name.

           

           

          //ExportPDF_in_Foreground.jsx

           

          //Uwe Laubender

           

          /**

           

          * @@@BUILDINFO@@@ ExportPDF_in_Foreground.jsx !Version! Wed Jun 23 2010 17:08:10 GMT+0200

           

          */

           

          //DESCRIPTION:PDF-Export in foreground (old school like in InDesign CS4)

           

           

           

          if(app.documents.length>0){

           

              var d=app.activeDocument;

           

              };

           

          else{

           

              alert("Please open a document to execute export to pdf. Script will be aborted.");

           

              exit();

           

              }

           

          if(d.saved == false){

           

              alert("Save your document first before executing export to pdf. Script will be aborted.");

           

              exit();

           

              };

           

           

           

          var pdfPath = Folder.selectDialog("Folder to save LOW RES pdf:");

          var docName = d.name;

          docName = docName.substring(0, docName.lastIndexOf(".indd"))

           

          var pdfName = docName + "_LOW.pdf";

           

           

           

          var userDefFileName = prompt("File name:",pdfName,undefined);

           

           

           

          if(userDefFileName == null){

           

              exit();

           

              };

           

           

           

          var pdfFullName = pdfPath+"/"+userDefFileName;

           

           

           

          if(File(pdfFullName).exists){

           

              c=confirm("The PDF-file \""+userDefFileName+"\" is already existing. Do you want to overwrite it?",true,undefined);

           

              if (c==0){exit()};  

           

              };

           

          //Error-handling if PDF file override is on and PDF is already opened in an PDF reader app:

           

          try{

           

          d.exportFile(ExportFormat.PDF_TYPE,File(pdfFullName),true,undefined,undefined);

           

          }catch(e){

           

              alert("Error:\r"+e.message+"\r\r(Line "+ e.line+" in script code.)");

           

              exit();

           

              };  

          • 2. Re: how to truncate the file name in this script
            Manan Joshi Adobe Community Professional

            I see the script asking the name of the pdf file in a prompt with a pre populated name, that name also does not match with what you mentioned. If the document name is Test.indd, the suggested name is Test.indd_LOW.pdf.

             

            Now if you want the suggested name to be just Test.pdf

            Change the following line of code to the one mentioned below it

             

            var pdfName = d.name+"_LOW.pdf";          //Replace this line with the one below it
            var pdfName = d.name.substring(0, d.name.indexOf("."))+"_LOW.pdf";
            

            -Manan

            • 3. Re: how to truncate the file name in this script
              Laubender Adobe Community Professional & MVP

              Hi Manan,

              better use this:

               

              var pdfName = d.name.replace(/\.indd$/i,"") + "_LOW.pdf" ;
              

               

              Imagine what will happen to a PDF exported from a document that is named like that:

              my.indd-doc-opened-with-CC-2019.indd

               

              Result string wth your suggestion:

              my_LOW.pdf

               

              Regards,
              Uwe

              • 4. Re: how to truncate the file name in this script
                Laubender Adobe Community Professional & MVP

                @Js1212  wrote

                 

                I found this "oldie but goodie" script and it is performing very well except the name of the PDF it produces includes the .indd

                for example Test.indd will create a PDF named Test.indd.pdf

                …   

                Hi @Js1212 ,

                I did that on purpose!

                To indicate the origin of the PDF. :-)

                 

                Best,
                Uwe

                • 5. Re: how to truncate the file name in this script
                  Manan Joshi Adobe Community Professional

                  Hi Uwe,

                   

                  Sure, i did not think of this use case. This solution would be better, you never know how someone would name his files, better to make the solution as robust as it gets. I admire the amount of thought you put towards seemingly simple problems and come up with use cases most of the people miss out.

                   

                  Thanks,

                  -Manan