0 Replies Latest reply on Sep 10, 2015 9:42 PM by arasank86029633

    Export Pdf script some doubts

    arasank86029633 Level 1

      Hi All,

       

      I have created export pdf some contions using script for below codes.

       

      my doubts for font and links missing not showing please advice.

       

       

      Description    :   process
         1. Active Document
         2. Check Missing Link, Missing Font
         3. Choose Destination Folder
         4. Choose PDF Export Preset
         5. Link update if needed
         6. Choose Bulk or Single Page
         7. If Sinlge Page Choose All Page or Selective Page
         8. Export as PDF

       

       

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

          alert("No File is Open");

          exit()

      }

      var myDoc;

      var myDocName;

      var myDocName_WO_EXTN;

      var myPDFExportPreset;

      var myPDFPresetList = new Array;

      var Pg_Chk_Box = new Array();

       

      var RepStr = "";

       

      var FLG_bulkPDF;

      var FLG_singlePagePDF;

      var FLG_FullDoc;

      var FLG_SelectPage;

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      myDoc = app.activeDocument;

      myDocName = myDoc.name.toString();

      myDocName = myDocName.replace(/%20/g, " ");

      myDocName_WO_EXTN = myDocName.replace(/.indd/i,"");

                 

      Doc_MissingFont()

      Doc_MissingLink()

       

      if(RepStr != ""){

          var f = new File(myDoc.filePath + "/"+myDocName_WO_EXTN+"_PDF_Export_Report.csv");

          f.open("w");

          f.write("InDesign Name,Missing Font,Missing Link, Text Overflow\n");

          f.write(RepStr);

          alert("PROCESS COMPLETED\n\n\nReport Generated in Document Path");

          exit()

      }

       

      var Desti_Folder = Folder.selectDialog("Choose the Destination Folder");

      if(Desti_Folder == null){

          alert("Folder not chosen");

          exit();

      }

       

      My_Dialog()

      alert("PROCESS COMPLETED");

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function My_Dialog(){

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

          for(var myCounter = 0; myCounter < app.pdfExportPresets.length; myCounter++){

              myPDFPresetList.push(app.pdfExportPresets[myCounter].name);

          }

       

          var myDialog = app.dialogs.add({name:"Export PDF"});

          with(myDialog){

              with(dialogColumns.add()){

                  with(dialogRows.add()){

                      var pdfButtonGroup = radiobuttonGroups.add();

                      with(pdfButtonGroup){

                          FLG_bulkPDF = radiobuttonControls.add({staticLabel:"Bulk PDF", checkedState:true});

                          FLG_singlePagePDF = radiobuttonControls.add({staticLabel:"Single Page PDF"});

                      }

                  }

                  with(dialogRows.add()){

                      staticTexts.add({staticLabel:"PDF Export Preset:"});

                      var myPDFPresetDropdown = dropdowns.add({stringList:myPDFPresetList, selectedIndex:0});

                  }

              }

          }

         

          var myResult = myDialog.show();

          if(myResult == true){

              myPDFExportPreset = myPDFPresetList[myPDFPresetDropdown.selectedIndex];

              Export_PDF();

          }

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function Export_PDF(){

      //SectionIncludePrefixs()

      UpdatingLinks();

       

      if(FLG_bulkPDF.checkedState == true){

          Bulk_PDF();

      }

      else if(FLG_singlePagePDF.checkedState == true){

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

          var myDialog2 = app.dialogs.add({name:"Export PDF"});

          with(myDialog2){

              with(dialogColumns.add()){

                  with(dialogRows.add()){

                      var pdfButtonGroup2 = radiobuttonGroups.add();

                      with(pdfButtonGroup2){

                          FLG_FullDoc = radiobuttonControls.add({staticLabel:"All Pages", checkedState:true});

                          FLG_SelectPage = radiobuttonControls.add({staticLabel:"Selected Pages", checkedState:true});

                         

                      }

                  }

              }

          }

          var myResult2 = myDialog2.show();

          if(myResult2 == true){   

              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;  

             

              if(FLG_FullDoc.checkedState == true){

                  SinglePage_PDF();

              }

              else if(FLG_SelectPage.checkedState == true){

                  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

       

                  var myDialog3 = app.dialogs.add({name:"Select Page", canCancel:true});

                      with(myDialog3){

                          with(dialogColumns.add()){

                              with(borderPanels.add()){

                                  with(dialogColumns.add()){

                                      for(i=0;i<myDoc.pages.length;i++){

                                          var pgNam = myDoc.pages[i].name.toString();

                                          Pg_Chk_Box[i] = checkboxControls.add({staticLabel:pgNam, checkedState:false});

                                      }

                                  }

                              }

                          }

                      }

         

                      var myRes3 = myDialog3.show()

                      if(myRes3 == true){

                          for(var pg=0;pg<myDoc.pages.length;pg++){

                              if(Pg_Chk_Box[pg].checkedState){

                                  var pagNam = myDoc.pages[pg].name.toString();

                                  var pre=myDoc.pages[pg].appliedSection.sectionPrefix;

                                  if(pre != ""){

                                      if(myDoc.pages[pg].appliedSection.includeSectionPrefix == true){

                                          pagNam=pre+pagNam;

                                      }

                                  }

                                 

                                  app.pdfExportPreferences.pageRange = pagNam;

                                 

                                  var pgNoFormat = PageNumberFormat(pagNam)

                                  var myPDFFile = new File(Desti_Folder+"/"+pgNoFormat+"_"+myDocName_WO_EXTN+".pdf");  

                            

                                  if(myPDFExportPreset == "Current PDF Export Settings"){

                                      myDoc.exportFile(ExportFormat.pdfType, myPDFFile);  

                                  }

                                  else{

                                      myDoc.exportFile(ExportFormat.pdfType, myPDFFile,0, myPDFExportPreset);

                                  }

                              }

                          }

                      }

                  }

              }

          }   

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function Bulk_PDF(){

          var myPDFFile = new File(Desti_Folder +"/" + myDocName_WO_EXTN +".pdf");  

                     

          if(myPDFExportPreset == "Current PDF Export Settings"){

              myDoc.exportFile(ExportFormat.pdfType, myPDFFile);  

          }

          else{

              myDoc.exportFile(ExportFormat.pdfType, myPDFFile,0, myPDFExportPreset);  

          }

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function SinglePage_PDF(){

          for(var pg=myDoc.pages.length-1;pg>=0;pg--){

              var pagNam = myDoc.pages[pg].name.toString();

              var pre=myDoc.pages[pg].appliedSection.sectionPrefix;

              if(pre != ""){

                  if(myDoc.pages[pg].appliedSection.includeSectionPrefix == true){

                      pagNam=pre+pagNam;

                  }

              }

              app.pdfExportPreferences.pageRange = pagNam;

              //alert("before pagNam: "+pagNam);

              var pgNoFormat = PageNumberFormat(pagNam)

              //alert("after pgNoFormat: "+pgNoFormat);

              var myPDFFile = new File(Desti_Folder+"/"+pgNoFormat+"_"+myDocName_WO_EXTN+".pdf");  

                            

              if(myPDFExportPreset == "Current PDF Export Settings"){

                  myDoc.exportFile(ExportFormat.pdfType, myPDFFile);  

              }

              else{

                  myDoc.exportFile(ExportFormat.pdfType, myPDFFile,0, myPDFExportPreset);  

              }

          }

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function PageNumberFormat(pgName){

          var num = pgName.match(/\d+/);

          num = Number(num);

       

          var rStr = "";

          if(num<10)                rStr = "00" + num;

          else if(num<100)        rStr = "0" + num;

          else                            rStr = num;

       

          rStr = rStr.toString();

          num = num.toString();

          var pgf = pgName.replace(num,rStr);

         

          return pgf;

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function UpdatingLinks(){

          for(var lnk=myDoc.links.length-1;lnk>=0;lnk--){

              try{

                  if(myDoc.links[lnk].status == 1819242340){

                      myDoc.links[lnk].update();

                  }

              }catch(e){}

          }

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function Doc_MissingFont(){

          var str1 = "#"+myDoc.fonts.everyItem().status.join("#")+"#";

          if(str1.match("#1718832705#") || str1.match("#1718834037#") || str1.match("#1433299822#")){

              var t2 = "#";

              var t2_2 = [];

              for(var fo=0;fo<myDoc.fonts.length;fo++){

                  if(myDoc.fonts[fo].status == 1718832705 || myDoc.fonts[fo].status == 1718834037 || myDoc.fonts[fo].status == 1718834037){

                      var fontfam = myDoc.fonts[fo].fontFamily;

                      if(t2.match(fontfam) == null){

                          t2 += fontfam + "#";

                          t2_2.push(fontfam);

                      }

                  }

              }

         

              for(var idx=0;idx<t2_2.length;idx++){

                  if(idx == 0){

                      RepStr += myDocName +",Missing Font,"+t2_2[idx]+"\n";

                  }

                  else{

                      RepStr += ",Missing Font,"+t2_2[idx]+"\n";

                  }

              }

             

              FLG_MissFont = true;           

          }

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function Doc_MissingLink(){

          var str = "#"+myDoc.links.everyItem().status.join("#")+"#";

          if(str.match("#1819109747#")){

              var t1 = "#";

              var t1_1 = [];

              for(var li=0;li<myDoc.links.length;li++){

                  if(myDoc.links[li].status == 1819109747){

                      var tmpN = myDoc.links[li].name.toString().replace(/%20/);

                      if(t1.match(tmpN) == null){

                          t1 += tmpN + "#";

                          t1_1.push(tmpN);

                      }

                  }

              }

         

              for(var idx=0;idx<t1_1.length;idx++){

                  if(idx == 0){

                      RepStr += myDocName +",Missing Link,"+t1_1[idx]+"\n";

                  }

                  else{

                      RepStr += ",Missing Link,"+t1_1[idx]+"\n";

                  }

              }

             

              FLG_MissLink = true;

          }

      }

      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------- - ------------------------------

      function SectionIncludePrefixs(){

          var myDoc=app.activeDocument;

          for(var sc=0;sc<myDoc.sections.length;sc++){

              myDoc.sections[sc].includeSectionPrefix = true;

          }

      }