Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

find text and get the page it is on

Return to Member Forum

  • Author
    Posts
    • #60090
      simondawdry
      Member

      Hi,

      I'm new to indesign scripting, and working with indesign server CS5 and Javascript.

      I'm working on a script to find text within an indd document, and retrieve the page(s) it appears on. I have this so far, cobbled together from various sources and hopefully some kind soul will take pity on me and have a look to see where I'm going wrong!

      result = (myFindResult + “is on page” + myPageName);myPageName = myFindResult.text.item(0).parentTextFrame.name;myFindResult = mySearch.item(0);mySearch = app.findTextPreferences.findWhat = “text”;

      Any suggestions gratefully received,

      Simon

    • #60092

      Hi Simon,

      Here is a simple example:

      var doc = app.activeDocument;
      // clear find change text preferences before search
      app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
      // this is scripting equivalent of the 'Find What:' edit text field
      app.findTextPreferences.findWhat = “text”;
      // search it in the active document
      // you can also search it in almost everywhere: story, text frame, paragraph, line, word, etc
      var finds = doc.findText();
      if (finds.length > 0) { // something has been found
      // for the 1st found item display the name of the page where the 1st text frame (there can be several threaded frames) containing it is located
      alert(“Found ” + finds.length + ” items, the first of them is on page ” + finds[0].parentTextFrames[0].parentPage.name);
      }
      else { // found nothing
      alert(“Nothing has been found”);
      }
      // clear find change text preferences after search
      app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

      Hope this helps.
      Kasyan

    • #60093

      I wrote this in desktop version of InDesign so that to demonstrate my approach. Alerts will not work in InDesign server.

    • #60094
      simondawdry
      Member

      fantastic, many thanks for the reply Kaysan, I'll give that code a go and let you know how I get on :-)

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Forum Ads