0 Replies Latest reply on Apr 21, 2016 7:40 AM by Johnwhite

    How to function the preflight checker

    Johnwhite Level 1

      Hi experts

       

      I have a script, which came from Kasyan, but the script has not function for check miss font, and overest text,

      how can I add a function for these kind of preflight check,

      how can make those code functioning?

       

      thanks

      Regard

      John

       

      the script:

       

      //======================================================================================
      var gScriptName = "Batch export INDD-files to PDF"; // Name of the script
      var gScriptVersion = "1.0"; // Version

      var gSet = GetSettings();
             CreateDialog();
            
      var
        mBooks = app.books.everyItem().getElements(),
        mDocs,
        cBook, cDoc;
           

      //===================================== FUNCTIONS  ======================================
      function CreateDialog() {
      var pdfPresetsList =app.pdfExportPresets.everyItem().name;
      var win = new Window("dialog", gScriptName + " - " + gScriptVersion);

      win.p = win.add("panel", undefined, "");
      win.p.alignChildren = "right";
      win.p.alignment = "fill";

      win.p.g = win.p.add("group");
      win.p.g.st = win.p.g.add("statictext", undefined, "PDF-presets:");
      win.p.g.ddl = win.p.g.add("dropdownlist", undefined, pdfPresetsList);
      win.p.g.ddl.selection = gSet.selectedPdfPresetIndex;
      win.p.g.ddl.preferredSize.width = 220;

      win.buttons = win.add("group");
      win.buttons.orientation = "row";  
      win.buttons.alignment = "center";
      win.buttons.ok = win.buttons.add("button", undefined, "OK", {name:"ok" });
      win.buttons.cancel = win.buttons.add("button", undefined, "Cancel", {name:"cancel"});

      var showDialog = win.show();

      if (showDialog == 1) {
        gSet.selectedPdfPresetIndex = win.p.g.ddl.selection.index;
        app.insertLabel("Kas_" + gScriptName + gScriptVersion, gSet.toSource());
        Main();
      }
      }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------
      function Main() {
      var folder = Folder.selectDialog("Select a folder with InDesign files to export");
      if (folder == null) exit();
      var files = GetFiles(folder);
      var pdfFolder = new Folder(folder.fsName + "/" + "Pdf");
      VerifyFolder(pdfFolder);

      if (files.length == 0) {
        alert("No files to open.", gScriptName + " - " + gScriptVersion);
        exit();
      }

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
      var pdfPresets =app.pdfExportPresets.everyItem().getElements();
      var selectedPdfPreset = pdfPresets[gSet.selectedPdfPresetIndex];
      var count = 1;
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

      // Progress bar -----------------------------------------------------------------------------------
      var progressWin = new Window ("window", gScriptName + " - " + gScriptVersion);
      var progressBar = progressWin.add ("progressbar", [12, 12, 350, 24], 0, files.length);
      var progressTxt = progressWin.add("statictext", undefined, "Starting exporting files");
      progressTxt.bounds = [0, 0, 340, 20];
      progressTxt.alignment = "left";
      progressWin.show();
      // Progress bar -----------------------------------------------------------------------------------

      for (var i = 0; i < files.length; i++) {
        var currentFile = files[i];
       
        try {
         var doc = app.open(currentFile, false);
         var docName = doc.name;

         // Progress bar -----------------------------------------------------------------------------------
         progressBar.value = count;
         progressTxt.text = String("Exporting file - " + docName + " (" + count + " of " + files.length + ")");
         // Progress bar -----------------------------------------------------------------------------------

         var file = new File(pdfFolder + "/" + GetFileName(docName) + ".pdf");
         if (file.exists) {
          var increment = 1;
          while (file.exists) {
           file = new File(pdfFolder + "/" + GetFileName(docName) + "(" + increment++ + ").pdf");
          }
         }
             
             
            

         doc.exportFile(ExportFormat.pdfType, file, false, selectedPdfPreset);
         doc.close(SaveOptions.NO);
         count++;
        }
        catch(e) {}
      }

      // Progress bar -----------------------------------------------------------------------------------
      progressWin.close();
      // Progress bar -----------------------------------------------------------------------------------

      alert("Done.", gScriptName + " - " + gScriptVersion);
      }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------
      function VerifyFolder(folder) {
      if (!folder.exists) {
        var folder = new Folder(folder.absoluteURI);
        var array1 = new Array();
        while (!folder.exists) {
         array1.push(folder);
         folder = new Folder(folder.path);
        }
        var array2 = new Array();
        while (array1.length > 0) {
         folder = array1.pop();
         if (folder.create()) {
          array2.push(folder);
         } else {
          while (array2.length > 0) {
           array2.pop.remove();
          }
          throw "Folder creation failed";
         }
        }
      }
      }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------
      function GetFiles(theFolder) {
      var files = [],
      fileList = theFolder.getFiles(),
      i, file;

      for (i = 0; i < fileList.length; i++) {
        file = fileList[i];
        if (file instanceof Folder) {
         files = files.concat(GetFiles(file));
        }
        else if (file instanceof File && file.name.match(/\.indd$/i)) {
         files.push(file);
                  }
              }

      return files;
         
        cDoc.close(SaveOptions.YES);
        }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------
      function checkFonts(cDoc)
      {
      var
        mFonts = cDoc.fonts.everyItem().getElements(),
        cFont;
      errMsg = "";
      while ( cFont = mFonts.pop() )
        if (cFont.status != FontStatus.INSTALLED) {
         errMsg = cDoc.name + " needs to check fonts";
         return false;
         }
      return true;
      }
      function checkLinks(cDoc)
                  {
               var link, image, frame;
               var openDocs = app.documents;
               var openDocsLen = openDocs.length;
               for (var d = 0; d < openDocsLen; d ++){
               currDoc = openDocs[d], 
               links = currDoc.links, 
               counter = 0; 
                   for (var i = links.length-1; i >= 0; i--) { 
                       if (links[i].status == LinkStatus.LINK_MISSING) { 
                                      errMsg = cDoc.name + " Need to check link";
                               return false;
                           } 
                       } 
                   }
                         return true;
                          }
      function checkText(cDoc)
      {
      var
        mStories = cDoc.stories.everyItem().getElements(),
        cStory, cFrames, cArray, cArray1, cCell,
        cTables = cDoc.stories.everyItem().tables.everyItem(),
        check,  step, cOver;
      errMsg = "";
      while ( cStory = mStories.pop() )
        if (cStory.overflows) {
         cFrames = cStory.textContainers;
         check = cFrames[cFrames.length-1].parentPage;
         if (cFrames[cFrames.length-1].parentPage){
          errMsg = cDoc.name + " needs to check text overset";
          return false;
          }
         }
       
      check = false;

      if (cTables.getElements().length) check = cTables.cells.everyItem().overflows.sort().reverse()[0];
      if (check){
        cArray = cTables.cells.everyItem().overflows;
        cArray1 = cTables.cells.everyItem().getElements();
        step = cArray1.length;
        while ( step -- ) {
         if (!cArray[step]) continue;
          cCell = cArray1[step];
          if (cCell.parent.parent.parentPage){
           errMsg = cDoc.name + " needs to check cell overset ";
           return false;
           }
         }
        } 
      return true;
      }
      function confirmDialog(cMsg)
      {
      var
        Msg = "At least 1 problem detected!\n",
        w = new Window("dialog", "before export checkPoint", undefined, {closeButton: false}),  
        mPanel = w.add("panel", undefined,"CheckPoint alert:"),
        mSpace = mPanel.add("group"),
        mStat = mPanel.add("statictext", undefined, Msg + cMsg, {multiline: true}),
        mButtons = w.add("group"),
         mGO = mButtons.add("button", undefined, "Process Anyway", {name:"OK"}),
         mBreak = mButtons.add("button", undefined, "Skip", {name:"Cancel"});
        mStat.graphics.font = ScriptUI.newFont ("Verdana", "Bold", 12);
        mStat.alignment = "left";
        mPanel.alignment = "fill";
        return w.show();
      }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------
      function GetFileName(fileName) {
      var string = "";
      var result = fileName.lastIndexOf(".");
      if (result == -1) {
        string = fileName;
      }
      else {
        string = fileName.substr(0, result);
      }
      return string;
      }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------
      function GetSettings() {
      var set = eval(app.extractLabel("Kas_" + gScriptName + gScriptVersion));
      if (set == undefined) {
        set = { selectedPdfPresetIndex : 0 };
      }
      return set;
      }
      //---------------------------------------------------------------------------------------- ----------------------------------------------------------------