Java: Add an Image Stamp to a Word Document

Import JAR Dependency


Add an Image Stamp to Word Document

  • Create a Document instance.
  • Load a Word document using Document.loadFromFile() method.
  • Get the specific paragraph using ParagraphCollection.get() method.
  • Add an image to the Word document using Paragraph.appendPicture() method.
  • Set position, size and wrapping style of the image using the methods offered by DocPicture class.
  • Save the document to another file using Document.saveToFile() method.
import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.fields.DocPicture;

public class AddStamp {
public static void main(String[] args) {
//Create a Document instance
Document doc = new Document();

//Load a Word document

//Get the specific paragraph
Section section = doc.getSections().get(0);
Paragraph paragraph = section.getParagraphs().get(4);

//Add an image
DocPicture picture = paragraph.appendPicture("cert.png");

//Set the position of the image

//Set width and height of the image

//Set wrapping style of the image to In_Front_Of_Text, so that it looks like a stamp

//Save the document to file
doc.saveToFile("AddStamp.docx", FileFormat.Docx);




Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Create a library that compiles to NPM and Jar with Kotlin Multiplatform

An overview of the challenges and experiences encountered during the project.

How to Use Override Annotation and the super Keyword in Dart.

Creating AWS Lambda Service in C#

Integration of Allure reports with Gitlab

Accident Lawyer Sandy Utah

accident lawyer sandy utah

Memoization technique for better time complexity

What is Elasticsearch? — Bot Techie

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Java in a different taste…!!!

Classes and Objects

First Java Program

Different calling forms of REST services with Feign client in Spring Cloud