Skip to main content
Participating Frequently
February 14, 2011
Answered

how can i show a text with findText()

  • February 14, 2011
  • 1 reply
  • 610 views

Dear,

I use findText() to search a string on a existing document !

I works when i use the lenght method it who's me the number fo item fiound.

I want to go the page where it have been find and make  selected the text found.


Thanks you for your help !

This topic has been closed for replies.
Correct answer milligramme

Hello

I do always this way.

select each result and zoom, you will jump to the page.

var doc = app.documents[0];
app.findTextPreferences = null;

//current zoom percentage
var zoom_bk = app.activeWindow.zoomPercentage;

//keyword
app.findTextPreferences.findWhat = "anytext";

//found collection
var result = app.findText();

for (var i=0; i < result.length; i++) {
     result.select();
     app.activeWindow.zoomPercentage = 400;
     //jump to each "anytext"
     alert(app.findTextPreferences.findWhat + " was found " + (i+1) + "/" + result.length);
};
app.activeWindow.zoomPercentage = zoom_bk;

mg

1 reply

milligramme
milligrammeCorrect answer
Inspiring
February 15, 2011

Hello

I do always this way.

select each result and zoom, you will jump to the page.

var doc = app.documents[0];
app.findTextPreferences = null;

//current zoom percentage
var zoom_bk = app.activeWindow.zoomPercentage;

//keyword
app.findTextPreferences.findWhat = "anytext";

//found collection
var result = app.findText();

for (var i=0; i < result.length; i++) {
     result.select();
     app.activeWindow.zoomPercentage = 400;
     //jump to each "anytext"
     alert(app.findTextPreferences.findWhat + " was found " + (i+1) + "/" + result.length);
};
app.activeWindow.zoomPercentage = zoom_bk;

mg

jeanmedAuthor
Participating Frequently
February 15, 2011

Thank you !