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...
A blog about Microsoft Office and PDF document development using .NET and Java.