3 Replies Latest reply on Aug 8, 2014 4:10 PM by HarveyLiu

    Can you fix this script problem?

    HarveyLiu

      Hi everyone

       

      I got this script

      for gen underline text to pdf

       

      the problem is it gen each page multi times if the page more then one place has underline text

       

      Can you fix it?

       

       

      //======================================================================

       

       

      var f = new Folder("~/Desktop/Revised_PDF put in here/"); 
      f.create();

      var doc = app.documents; 
      app.findTextPreferences = null; 
      app.findTextPreferences.underline = true; 
      for(var i=0;i<doc.length;i++) 

              var found = doc[i].findText(); 
              var _pages = []; 
              for(var j=0;j<found.length;j++) 
              { 
                      var txfms = found[j].texts[0].parentTextFrames; 
                      for(var k=0;k<txfms.length;k++) 
                      { 
                              _pages.push(txfms[k].parentPage.name); 
                          } 
                  } 
              for(var j=0;j<_pages.length;j++) 
              { 
                      if(_pages[j] === _pages[j-1]) 
                      { 
                              _pages.splice(j,1); 
                          } 
                  } 
              if(_pages.length != 0) 
              { 
                      app.pdfExportPreferences.pageRange = _pages.toString(); 
                      doc[i].exportFile(ExportFormat.PDF_TYPE, new File("~/Desktop/Revised_PDF put in here/" + doc[i].name.replace(/\.indd$/i,".pdf")), false);
                  } 
              _pages = []; 
          } 
      app.findTextPreferences = null;

      alert("Done.");

      var f = Folder("~/Desktop/Revised_PDF put in here/" ); 
      f.execute(); 

       

       

      //======================================================================

       

       

       

      for specific details:

       

      Is that possible to write a script for export underline text to PDF?

       

       

      thanks

       

      Harvey

        • 1. Re: Can you fix this script problem?
          [Jongware] Most Valuable Participant

          > the problem is it gen each page multi times if the page more then one place has underline text

           

          Is this only when you have multiple unconnected text frames (each one containing underlined text) on the same page? Or possibly footnotes, tables, or anchored text?

           

          Chinna's script assumes all text is in a single threaded story: the findText command searchs one story at a time, from start to end (and across multiple pages). If it reaches the end of the story, it continues with the next one, even if it has to go back to the first page. And anchored objects, text in tables, and text in footnotes all count as "separate texts".

           

          Chinna's script already removes multiple pages:

           

          for(var j=0;j<_pages.length;j++)
          {
            if(_pages[j] === _pages[j-1])
            {
              _pages.splice(j,1);
            }
          }
          

           

          but it only works for a continuous story, because the "found" occurrences will be in the original page order, such as "1,2,2,3,5,5". This code removes successive doubles (see the Javascript documentation for a description of "splice"). As soon as you have separate stories (tables, 'notes, et cetera), you get a series such as "1,3,3,5,1,6" -- where "1,6" would be the occurrences in a separate story.

           

          The solution is simple: before removing the duplicates, sort the pages. As far as scripting goes, this is remarkably easy:

           

          _pages.sort();
          

           


           

          Please note that I just felt like answering your question this once. If you do what you did on most some of your other questions (ask for multiple versions for other formatting, have a different functionality, work on "selected documents" or "all in a folder" or "in a book file", or follow up with questions about totally unrelated scripts) I will probably not answer anymore.

          No offense meant, of course.

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

            Hi Jongware

             

            thank you for your help

             

            it works in multi text frame, my be I have to test in other ways

             

            for example: underline text in master

             

            Regard

             

            Harvey

            • 3. Re: Can you fix this script problem?
              HarveyLiu Level 1

              Hi Jongware

               

              I changed into this:


                      for(var j=0;j<_pages.length;j++)

                      {

                              if(_pages[j] === _pages[j-1])

                              {

                                _pages.sort();

                                  }

                          }

               

              but still gen multi times for one page

               

              Harvey