These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Finding text based off of a rect

Script Kitty
Registered: Jul 9 2010
Posts: 19

For those looking to do this, I had made a post before but forgot to follow up...

Finding the rect of the current selection (select the area you want with the rect annotation tool then execute this code to get its coordinates):
        console.println(getAnnots(this.pageNum)[0].rect);
Finding all text on page inside of the rect:

	//Parameters
	var target = [193, 189, 413, 665];
//or	var target = getAnnots(this.pageNum)[0].rect;
	var page = 0;
	//Body
	var result = "";
	var selection;
	for(var i = 0;i < this.getPageNumWords(page);i++){
		selection = this.getPageNthWordQuads(page,i);console.println(''); 
		if(target[0] < selection[0][0]
		&& target[1] < selection[0][5]
		&& target[2] > selection[0][2]
		&& target[3] > selection[0][3]){
			result += this.getPageNthWord(page,i) + ' ';
		}
	}
	//Return
	console.println(result);

ITFLA
Registered: Jan 28 2011
Posts: 3
I found a necessary adjustment for doing this for links. The text boundaries do not necessarily ALL fall within the Link rectangle so I needed to test for whether they overlapped instead. That is, ensure that the left of the text rectangle is LEFT of the RIGHT side of the link rectangle AND the RIGHT is RIGHT of the LEFT side... top above the bottom, bottom below top, etc.