Skip to main content

Posts

Showing posts with the label search text

Search and Highlight Text in PDF in Java

Highlighting text can help users quickly jump to the location of the text in a document. In this blog, I will introduce how to search specific text in a PDF document and highlight the searched text in Java application. The below example uses Free Spire.PDF for Java library. The sample PDF document looks like below: import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; import com.spire.pdf.general.find.PdfTextFind; import java.awt.*; public class HighlightText {     public static void main(String[] args) throws Exception     {         //load the PDF file         PdfDocument pdf = new PdfDocument();         pdf.loadFromFile( "Additional.pdf" );         PdfTextFind[] result;         //loop through the pages in the PDF file    ...