Skip to main content

Posts

Showing posts from August, 2019

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         for (PdfPageBase page:(Iterable<PdfPageBase>) pdf.getPages())         {             //search the text "The Man Who Laughs" on every PD

Replace Image in Word in Java

In this article, I will introduce how to replace an image with a new image and how to replace an image with text in a Word document programmatically in Java. The required library: Free Spire.Doc for Java The example Word document: Imported namespace: import com.spire.doc.Document; import com.spire.doc.DocumentObject; import com.spire.doc.FileFormat; import com.spire.doc.Section; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.DocPicture; import com.spire.doc.fields.TextRange;   Replace image with new image //load Word document Document doc = new Document(); doc.loadFromFile( "Images.docx" ); //get the first section Section section = doc.getSections().get( 0 ); //loop through the paragraphs in the section for ( int i= 0 ;i< section.getParagraphs().getCount();i++) {     Paragraph para=section.getParagraphs().get(i); //loop through the child objects in the p