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);