2 Replies Latest reply on Jul 28, 2014 1:55 PM by HarveyLiu

    Can you fix my script problem?

    HarveyLiu Level 1

      Hi everyone


      I got this script:


      function: gen specify color of text to pdf

      everything was very well, unless final step, I want to the script keep the new file's name as same as my indesign file's name,

      and no need to type in (".pdf")



      Thank you all so much!






      var doc = app.properties.activeDocument && app.activeDocument; 

      if (!doc) {alert("Adiós Amigo") ; exit();} 

      var sN = doc.swatches.everyItem ().name, 

          sID = doc.swatches.everyItem ().id, 


          /** UI */ 

          w = new Window ('palette', "Print by Color"), 

          g1 = w.add('group'), 

          g2 = w.add('group'), 

          st = g1.add('statictext', undefined, "Select Swatch from Drop Down List") 

          d = g1.add('dropdownlist', undefined, sN), 

          b1 = g2.add('button', undefined, "PDF"), 

          b2 = g2.add('button', undefined, "Print"); 


          b1.onClick = function () {proccessPages (d.selection, true)} 

          b2.onClick = function () {proccessPages (d.selection)} 



      function proccessPages (s, e) { 

          var l, c = 0, o, p, pO = {}, pA = []; 

          if (s == null) {alert("No Swatch Selected") ; return;}; 

          app.findTextPreferences = app.changeTextPreferences = null; 

          s = doc.swatches.itemByID (sID[s.index]); 

          app.findTextPreferences.fillColor = s; 

          var pageFinds = doc.findText (); 

          if (!(l = pageFinds.length)) {alert("No finds") ; return;}; 

          for (c = 0; c < l; c++) { 

              o = (p = pageFinds[c].parentTextFrames[0].properties.parentPage) && p.documentOffset + 1; 

              if (p) pO["_" + o] = o; // if the finds on a page add to page list 


          c = 0; 

          for (o in pO) pA[c++] = pO[o]; 

          var pageRange = "+" + pA.join(", +"); 

          doc.printPreferences.pageRange = pageRange; 

          if (!e) doc.print(true); 

          else { 

              app.pdfExportPreferences.pageRange = pageRange; 

              f = File.saveDialog("Export PDF", "PDF: *.PDF"); 

              if (!f) return; 

            app.activeDocument.exportFile (ExportFormat.PDF_TYPE, File(exportPath+'/'+linkname.name.replace(/(\.[^.]+)$/, '.pdf')), false, app.pdfExportPresets.item(exportPreset)); 





        • 1. Re: Can you fix my script problem?
          Jump_Over Level 5


          everything was very well, unless final step...


          app.activeDocument.exportFile (ExportFormat.PDF_TYPE, File(exportPath+'/'+linkname.name.replace(/(\.[^.]+)$/, '.pdf')), false, app.pdfExportPresets.item(exportPreset));


          Hi Harvey,


          Be honest, it can not work. There no exportPath, linkname and exportPreset in your code.

          You pasted it from a several independent codes and ask for help to fix it ==> but, to tell you the true, is nothing to fix.


          It reminds me very much one story happened to some guy somewhere:

          He was asked by a stranger:

          "Which way is shortest to another part of the city."


          The guy knew the city pretty well but explaining the way took a minutes.

          At the end, nonetheless, a stranger jumped to a guy's back and ask:

          "Could you kindly take me there, pls?"



          • 2. Re: Can you fix my script problem?
            HarveyLiu Level 1

            thank you Jarek


            for tell me the Truth