Insert Shape in Word using C#

Follow this article to insert shape in Word using C#. It has the details to set the development environment, a list of steps to write the application, and a sample code for drawing diagrams in Word using C#. You will learn to insert various shapes such as inline and floating shapes in an existing or a new Word file.

Steps to Insert Shapes in Word using C#

  1. Prepare the environment to insert shapes in a Word file using Aspose.Words for .NET
  2. Create an empty Word file using the Document class to use digital art
  3. Create the DocumentBuilder class object for the above document for adding straight line
  4. Insert a straight line as an inline shape and set the rotation angle
  5. Insert a free-floating shape with rotation angle
  6. Create the OoxmlSaveOptions class object and set the compliance mode
  7. Save the output with the above settings

These steps summarize how to draw a straight line in Word using C#. Create a new Word file, link a DocumentBuilder class object with it, and insert a shape of type line by passing the width, height, and rotation angle. Add another floating shape, like an arrow, by specifying the necessary parameters, then save the Word document with the required compliance settings.

Code for Adding Digital Art using Shapes in MS Word using C#

This sample code has taught us how to make a diagram in Word using C#. The simplest method is to insert an inline diagram by providing the shape type and its width and height. However, you may use other overloaded methods to create a floating diagram over the text by setting the top, left position, and height width of the new diagram, including the wrap type and relative positions with respect to the page.

This article has covered the information on how to draw shapes in Word using C#. If you want to insert a watermark, refer to the article on how to insert watermark in Word document using C#.

 English