Hi Aspose support!
I need to highlight a multilines phrase if PDF file and I used this code:
String text = "and interactive exercises";
Document doc = new Document(file.getInputStream());
Pattern re = Pattern.compile("(?i)" + text.replace(" ", "\\s*") + "\\b", Pattern.MULTILINE);
TextFragmentAbsorber tfa = new TextFragmentAbsorber(re,
new TextSearchOptions(true));
doc.getPages().get_Item(1).accept(tfa);
for(TextFragment tf : tfa.getTextFragments()){
HighlightAnnotation highlightAnnotation = new HighlightAnnotation(tf.getPage(), tf.getRectangle());
highlightAnnotation.setColor(Color.getGreenYellow());
tf.getPage().getAnnotations().add(highlightAnnotation);
}
doc.save("/home/hossam/Downloads/" + "PDF_Highlighting_2.pdf");
and its working fine for me but the problem is it highlight all the lines which contains the phrase like this:
Screenshot from 2020-12-01 13-35-30.png (34.4 KB)
but I need to highlight just “owed to the”, so please any advice here?
Thanks in advance.