Insert Shapes in Word using Java

This article explains how to insert shapes in Word using Java. It provides a reference to the resources required for setting the IDE, a list of steps, and a sample code demonstrating how to make a diagram in Word using Java. You will learn to insert inline and floating shapes in the Word document using a few API calls.

Steps for Drawing Diagrams in Word using Java

  1. Set the environment to use Aspose.Words for Java to insert shapes
  2. Create an empty Word file using the Document class for adding drawings in a DOCX file
  3. Insert an inline shape using the insertShape() method with the required parameters
  4. Insert a floating shape on the text using another overloaded method with respective arguments
  5. Set the rotation of each shape if required
  6. Define the OoxmlSaveOptions object and set the save format and compliance
  7. Save the output file

These steps describe how to add diagrams in Word using Java. Instantiate an object of the Document class to load or create a Word file, link the file with the DocumentBuilder object, and insert an inline shape providing shape type and size. Insert another floating shape by setting the shape type, position, size, wrap type, and relative position attributes.

Code for Inserting Digital Art using Shapes in MS Word using Java

This code snippet shows how to draw a straight line in Word using Java. We have demonstrated LINE and ARROW shapes however, you may try adding images, text boxes, rectangles, diamonds, triangles, parallelograms, thick arrows, arcs, and donut, etc. You may also set the wrap type to inline, top-bottom, square, tight, through, or none.

This tutorial has guided us on how to draw shapes in Word using Java. Besides, if you want to insert bullets, refer to the article on Insert bullets in Word using Java.

 English