using IronWord;
using IronWord.Models;
// Load docx
WordDocument doc = new WordDocument();
// Configure image
IronWord.Models.Image image = new IronWord.Models.Image("salvatore-tonnara.jpg");
image.Width = 200; // In unit pixel
image.Height = 200; // In unit pixel
Paragraph paragraph = new Paragraph();
// Add image
paragraph.AddImage(image);
// Add paragraph
doc.AddParagraph(paragraph);
// Export docx
doc.SaveAs("save_document.docx");
Imports IronWord
Imports IronWord.Models
' Load docx
Private doc As New WordDocument()
' Configure image
Private image As New IronWord.Models.Image("salvatore-tonnara.jpg")
image.Width = 200 ' In unit pixel
image.Height = 200 ' In unit pixel
Dim paragraph As New Paragraph()
' Add image
paragraph.AddImage(image)
' Add paragraph
doc.AddParagraph(paragraph)
' Export docx
doc.SaveAs("save_document.docx")
Install-Package IronWord
Add Image
The code snippet above loads a Word document and configures an image with specific dimensions. A new Paragraph object is then instantiated to contain the image, which is added using the AddImage method of the paragraph. This paragraph, now containing the image, is subsequently added to the document using AddParagraph. Finally, the modified document is exported.
Related Docs Links
Ready to get started? Version: 2024.10 just released