Word Image can beautify the document to attract more readers. Generally speaking, images in Word are related to contents. For example, the image will be places of interest if the document focuses on introducing one country. Sometimes, image can describe some of contents more clearly, like using chart to show data changes in a period.
Spire.Doc for .NET, a professional .NET word component to fast generate, open, modify and save Word documents without using MS Office Automation, enables users to insert image in Word and set its size according to page by using C#, VB.NET. This guide introduces an easy method how to insert image via Spire.Doc for .NET.
At first, create new Word document and add section, page for this document. Then, use p.AppendPicture(Image) method to insert image in the new created paragraph. Set height and width property for image to format its size. Download and Install Spire.Doc for .NET. Use the following code to insert image in Word by using C#, VB.NET.
using System.Drawing; using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace WordImage { class ImageinWord { static void Main(string[] args) { //Create Document Document document = new Document(); Section s = document.AddSection(); Paragraph p = s.AddParagraph(); //Insert Image and Set Its Size DocPicture Pic = p.AppendPicture(Image.FromFile(@"E:\Work\Documents\SampleImage\Sample.jpg")); Pic.Width = 750; Pic.Height = 468; //Save and Launch document.SaveToFile("Image.docx", FileFormat.Docx); System.Diagnostics.Process.Start("Image.docx"); } } }
Imports System.Drawing Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Namespace WordImage Friend Class ImageinWord Shared Sub Main(ByVal args() As String) 'Create Document Dim document As New Document() Dim s As Section = document.AddSection() Dim p As Paragraph = s.AddParagraph() 'Insert Image and Set Its Size Dim Pic As DocPicture = p.AppendPicture(Image.FromFile("E:\Work\Documents\SampleImage\Sample.jpg")) Pic.Width = 750 Pic.Height = 468 'Save and Launch document.SaveToFile("Image.docx", FileFormat.Docx) System.Diagnostics.Process.Start("Image.docx") End Sub End Class End Namespace
Spire.Doc, an easy-to-use .NET Word component, enables users to fast generate, open, save and modify Word document on .NET, WPF and Silverlight applications without Word automation and any other third party add-ins.