How to Add Image to DOCX

Images can be used to add visual context to an existing word document. To describe a sentence, a paragraph, or just a plain block of text. Adding images to a Word document (.docx) are made simple and straightforward with IronWord (A C# library for working with DOCX files). This tutorial will cover the essentials of adding images to a .docx file within a .NET environment.

Try IronWord

Start using IronWord in your project today with a free trial.

First Step:
green arrow pointer


Adding an Image

An image is referred programatically using its defined path in the local system. Firstly, instantiate the ImageContent class by providing the file path in string. Then, the image variable can be used all throughout the file in various locations or just to modify its properties, e.g. width, height. Finally, add the image to the .docx file using the AddImage() function. Once added, the document can be exported and saved locally. In the example below, we are adding the image inside the document without any parent node. The supported file formats are: .jpg, .png, .bmp, .tiff, .gif.

TipsAn image can be inserted as a child element within a paragraph for better document hierarchy. The paragraph can also define text wrapping and other text formatting properties.

:path=/static-assets/word/content-code-examples/how-to/add-image-insert-image.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;

// initializing docx file
WordDocument doc = new IronWord.WordDocument();

// instantiating image file
IronWord.Models.ImageContent image = new IronWord.Models.ImageContent("sample-image.jpg");

// modifying image properties
image.Width = 200;
image.Height = 200;

// AddImage function saving the image
doc.AddImage(image);

// Save and export the file
doc.SaveAs("inserted-image.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
Add image

Adding Image via Stream

Images which are served locally or via a static URL are quite easy to directly add into a .docx file using the previous method. To add images which are behind a secure API, requiring authentication, the Stream method would be appropriate. In the example below, an HTTP client sends authorization tokens to the server, retrieves the authenticated image stream upon verification, and integrates it directly before exporting the final .docx file.

:path=/static-assets/word/content-code-examples/how-to/add-image-insert-image-via-http-stream.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;

// initializing docx file
WordDocument doc = new IronWord.WordDocument();

using (HttpClient client = new HttpClient())
{
    // Add authentication headers
    client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY_HERE");
    client.DefaultRequestHeaders.Add("User-Agent", "MyApp/1.0");

    // Get image from authenticated endpoint
    Stream authenticatedStream = client.GetStreamAsync("https://api.example.com/secure/image.png");
    doc.AddImage(authenticatedStream);
}

// Export docx
doc.SaveAs("added-image-via-http-stream.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Modifying image properties

IronWord provides default customization methods for an image.

Settings Description Example
Width Horizontal dimension of the image in pixels image.Width = 500;
Height Vertical dimension of the image in pixels image.Height = 300;
WrapText Text wrapping behavior around the image image.WrapText = WrapText.Square;
DistanceFromLeft Spacing measurement from left edge in pixels image.DistanceFromLeft = 10;
DistanceFromRight Spacing measurement from right edge in pixels image.DistanceFromRight = 10;
DistanceFromTop Spacing measurement from top edge in pixels image.DistanceFromTop = 15;
DistanceFromBottom Spacing measurement from bottom edge in pixels image.DistanceFromBottom = 15;
Position Spatial placement information (X and Y coordinates) image.Position = new ElementPosition(50, 100);
Scale Proportional sizing factors for X and Y axes image.Scale = new PointF(1.5f, 1.5f);
Translate Displacement coordinates for repositioning image.Translate = new PointF(20, 30);

Customizing Width & Height

Custom width and height can be implemented altering predefined aspect ratio. An example is shown below.

:path=/static-assets/word/content-code-examples/how-to/add-image-custom-size.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;

// initializing docx file
WordDocument doc = new IronWord.WordDocument();

// instantiating image file
IronWord.Models.ImageContent image = new IronWord.Models.ImageContent("sample-image.tiff");

// modifying the aspect ratio by introducing custom width
image.Width = 800;
image.Height = 200;

// AddImage function saving the image
doc.AddImage(image);

// Save and export the file
doc.SaveAs("custom-size-image.docx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel
Add Image Custom Size

Frequently Asked Questions

How can I add an image to a DOCX file using C#?

You can add an image to a DOCX file programmatically in C# by utilizing IronWord. It allows you to easily manipulate Word documents, including inserting images.

What types of images can be added to a DOCX using IronWord?

IronWord supports various image formats, including JPEG, PNG, BMP, and GIF, which can be added to a DOCX file.

Is it possible to position images within a Word document using IronWord?

Yes, IronWord allows precise control over image positioning within a Word document, enabling you to specify locations and alignment.

Can I add multiple images to a single Word document with IronWord?

Absolutely. IronWord supports adding multiple images to a single Word document, allowing for complex document layouts.

Does IronWord support adding images to headers and footers?

Yes, IronWord can be used to add images to both headers and footers within a Word document, enhancing your document's design.

How does IronWord handle image scaling and resizing?

IronWord provides functionality to scale and resize images as they are added to a Word document, ensuring they fit seamlessly within the layout.

Can I add captions to images in a DOCX file using IronWord?

Yes, IronWord allows you to add captions to images, enhancing the clarity and context within your Word documents.

Is it possible to replace an existing image in a Word document using IronWord?

IronWord enables you to replace existing images in a Word document, offering flexibility in document updates and edits.

What are the system requirements for using IronWord to add images to DOCX files?

IronWord requires .NET framework support and is compatible with Windows, macOS, and Linux environments for adding images to DOCX files.

Can I automate the process of adding images to DOCX files using IronWord?

Yes, IronWord facilitates automation of the image addition process within DOCX files, streamlining document creation and editing tasks.

Ahmad Sohail
Full Stack Developer

Ahmad is a full-stack developer with a strong foundation in C#, Python, and web technologies. He has a deep interest in building scalable software solutions and enjoys exploring how design and functionality meet in real-world applications.

Before joining the Iron Software team, Ahmad worked on automation projects ...

Read More
Ready to Get Started?
Nuget Downloads 25,549 | Version: 2025.11 just released