diff --git a/libraries/pom.xml b/libraries/pom.xml
index 15446975f3..c7c5da95a6 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -601,6 +601,16 @@
wurmloch-crdt
${crdt.version}
+
+ org.docx4j
+ docx4j
+ 3.3.5
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.1
+
diff --git a/libraries/src/main/java/com/baeldung/docx/Docx4jExample.java b/libraries/src/main/java/com/baeldung/docx/Docx4jExample.java
new file mode 100644
index 0000000000..b3db8d0284
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/docx/Docx4jExample.java
@@ -0,0 +1,106 @@
+package com.baeldung.docx;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.List;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+
+import org.docx4j.dml.wordprocessingDrawing.Inline;
+import org.docx4j.jaxb.Context;
+import org.docx4j.model.table.TblFactory;
+import org.docx4j.openpackaging.exceptions.Docx4JException;
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
+import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
+import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
+import org.docx4j.wml.BooleanDefaultTrue;
+import org.docx4j.wml.Color;
+import org.docx4j.wml.Drawing;
+import org.docx4j.wml.ObjectFactory;
+import org.docx4j.wml.P;
+import org.docx4j.wml.R;
+import org.docx4j.wml.RPr;
+import org.docx4j.wml.Tbl;
+import org.docx4j.wml.Tc;
+import org.docx4j.wml.Text;
+import org.docx4j.wml.Tr;
+
+public class Docx4jExample {
+
+ public void createDocumentPackage(String outputPath, String imagePath) throws Exception {
+ WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
+ MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
+ mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
+ mainDocumentPart.addParagraphOfText("Welcome To Baeldung!");
+ ObjectFactory factory = Context.getWmlObjectFactory();
+ P p = factory.createP();
+ R r = factory.createR();
+ Text t = factory.createText();
+ t.setValue("Welcome To Baeldung");
+ r.getContent().add(t);
+ p.getContent().add(r);
+ RPr rpr = factory.createRPr();
+ BooleanDefaultTrue b = new BooleanDefaultTrue();
+ rpr.setB(b);
+ rpr.setI(b);
+ rpr.setCaps(b);
+ Color red = factory.createColor();
+ red.setVal("green");
+ rpr.setColor(red);
+ r.setRPr(rpr);
+ mainDocumentPart.getContent().add(p);
+
+ File image = new File(imagePath);
+ byte[] fileContent = Files.readAllBytes(image.toPath());
+ BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, fileContent);
+ Inline inline = imagePart.createImageInline("Baeldung Image", "Alt Text", 1, 2, false);
+ P Imageparagraph = addImageToParagraph(inline);
+ mainDocumentPart.getContent().add(Imageparagraph);
+
+ int writableWidthTwips = wordPackage.getDocumentModel().getSections().get(0).getPageDimensions()
+ .getWritableWidthTwips();
+ int columnNumber = 3;
+ Tbl tbl = TblFactory.createTable(3, 3, writableWidthTwips / columnNumber);
+ List