I have an article, and I want highlight the paragraph which in different page.
I already referenced "Find and Highlight Text in PDF in Java" in website, like this:
- Code: Select all
public class SpirePdfHighlight {
public static void main(String[] args) throws Exception {
// Load the document from disk
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("C:\\Users\\Desktop\\10.pdf");
pdf.getPages().add();
PdfTextFind[] result = null;
for (Object pageObj : pdf.getPages()) {
PdfPageBase page = (PdfPageBase) pageObj;
// Find text
result = page.findText("You can’t get hold of a mask at all", false).getFinds();
for (PdfTextFind find : result) {
// Highlight searched text
find.applyHighLight();
}
}
String output = "C:\\Users\\Desktop\\TEST\\Spire.pdf";
// Save the document
pdf.saveToFile(output, FileFormat.PDF);
}
}
But obviously, it can highlight only in the same page.
So I would like to ask for help... is there any way to highlight the paragraph which in different page?
THX!!