DocumentBuilder provides several overloads of the InsertImage method that allow you to insert an inline or floating image from a file or .NET Image object. If the image is an EMF or WMF metafile, it will be inserted into the document in metafile format. All other images will be stored in PNG format.
The InsertImage method can use images from different sources:
- From a file or URL
- From a stream
- From a .NET Image object
The InsertImage method allows you to insert an image with the following options:
- Inline or floating at a specific position.
- Percentage scale or custom size
The InsertImage method returns a Shape object that was just created and inserted and you can further modify properties of the Shape.
Inserting an Inline Image
Pass a single string representing a file that contains the image to InsertImage to insert the image into the document as an inline graphic.
Example DocumentBuilderInsertInlineImage
Shows how to insert an inline image at the cursor position into a document.
[C#]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(MyDir + "Watermark.png");
[Visual Basic]
Dim doc As Document = New Document()
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.InsertImage(MyDir & "Watermark.png")
[Java]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getMyDir() + "Watermark.png");
Inserting a Floating (Absolutely Positioned) Image
This example inserts a floating image from a file or URL at a specified position and size
Example DocumentBuilderInsertFloatingImage
Shows how to insert a floating image from a file or URL.
[C#]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(MyDir + "Watermark.png",
RelativeHorizontalPosition.Margin,
100,
RelativeVerticalPosition.Margin,
100,
200,
100,
WrapType.Square);
[Visual Basic]
Dim doc As Document = New Document()
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
builder.InsertImage(MyDir & "Watermark.png", RelativeHorizontalPosition.Margin, 100, RelativeVerticalPosition.Margin, 100, 200, 100, WrapType.Square)
[Java]
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getMyDir() + "Watermark.png",
RelativeHorizontalPosition.MARGIN,
100,
RelativeVerticalPosition.MARGIN,
100,
200,
100,
WrapType.SQUARE);