DocumentBuilderInsertImage Method (String)
Inserts an image from a file or URL into the document. The image is inserted inline and at 100% scale.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.10
Syntax
public Shape InsertImage(
	string fileName
)

Parameters

fileName
Type: SystemString
The file with the image. Can be any valid local or remote URI.

Return Value

Type: Shape
The image node that was just inserted.
Remarks

This overload will automatically download the image before inserting into the document if you specify a remote URI.

You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

Examples
Shows how to insert an image into a document from a web address.
[C#]

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(AsposeLogoUrl);

doc.Save(ArtifactsDir + "DocumentBuilder.InsertImageFromUrl.doc");
Examples
Shows how to inserts an image from a URL. The image is inserted inline and at 100% scale.
[C#]

// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();

builder.Write("Image from local file: ");
builder.InsertImage(MyDir + "Images/Aspose.Words.gif");
builder.Writeln();

builder.Write("Image from an Internet url, automatically downloaded for you: ");
builder.InsertImage(AsposeLogoUrl);
builder.Writeln();

builder.Document.Save(ArtifactsDir + "Image.CreateFromUrl.doc");
Examples
Shows different solutions of how to import an image into a document from a string.
[C#]

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("\nInserted image from string: ");
builder.InsertImage(ImageDir + "Aspose.Words.gif");

builder.Writeln("\nInserted image from string with a custom size: ");
builder.InsertImage(ImageDir + "Aspose.Words.gif", ConvertUtil.PixelToPoint(250),
    ConvertUtil.PixelToPoint(144));

builder.Writeln("\nInserted image from string using relative positions: ");
builder.InsertImage(ImageDir + "Aspose.Words.gif", RelativeHorizontalPosition.Margin, 100, 
    RelativeVerticalPosition.Margin, 100, 200, 100, WrapType.Square);

doc.Save(ArtifactsDir + "InsertImageFromString.docx");
Examples
Shows how to insert a floating image in the middle of a page.
[C#]

// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();

// By default, the image is inline.
Shape shape = builder.InsertImage(MyDir + "Images/Aspose.Words.gif");

// Make the image float, put it behind text and center on the page.
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.VerticalAlignment = VerticalAlignment.Center;

builder.Document.Save(ArtifactsDir + "Image.CreateFloatingPageCenter.doc");
See Also