This tutorial will guide you step-by-step as to how to add image in word document using C#. We’ll use a command-line application in C# add image to word document.
Steps to Add Image in Word Document using C#
- Add reference to System.Drawing assembly in solution
- Next, Aspose.Words for .NET NuGet package reference needs to be added
- Add using directives for Aspose.Words and Aspose.Words.Drawing namespaces
- Call License.SetLicense method
- Create Document object to load Word DOC from file system or memory stream
- Create DocumentBuilder class object to write text, images, tables etc.
- Move cursor to Header or Footer or any desired position in Word DOC
- Use DocumentBuilder.InsertImage to add image from stream or file
- Use Shape class to further set Size, Position, Fill etc. of the Image
- Call Document.Save method to save Word DOC to disk or stream
You can use the following code example in .NET application to add image to word document using C#.
Code to Add Image in Word Document using C#
So, the above Visual Studio application will allow you to add image to word document C#. It loads an existing DOC file but you can even programmatically create word document in C#. The code presents two ways to add image to word DOC C# - it first insert image in word document header C# and then it adds image to word as linked image i.e. the image in this case is not embedded but inserted as link to file.