Skip to main content
A newer version of this page is available. .

How to: Insert a Picture

The RichEditDocumentServer supports the following graphic types:

  • Bitmap (*.bmp, *.dib)
  • JPEG File Interchange Format (*.jpg, *.jpeg)
  • Portable Network Graphics (*.png)
  • Graphics Interchange Format (*.gif)
  • Tagged Image Format (*.tif, *.tiff)
  • Microsoft Enhanced Metafile (*.emf)
  • Windows Metafile (*.wmf)

Use the following API to place an image in the document:

API

Description

DocumentImageCollection.Append

Appends an image.

DocumentImageCollection.Insert
ShapeCollection.InsertPicture

Inserts an image in the specified position.

The code sample belows inserts an image at the document’s start.

Document document = server.Document;
DocumentPosition pos = document.Range.Start;
document.Images.Insert(pos, DocumentImageSource.FromFile("Documents\\beverages.png"));

The created DocumentImage object is added to two collections: ShapeCollection and DocumentImageCollection. The object’s Shape.TextWrapping property will be set to TextWrappingType.InLineWithText.

The code sample below inserts an image in the specified position. The resulting object is added to the ShapeCollection only.

Document document = server.Document;
document.AppendText("Line One\nLine Two\nLine Three");
Shape myPicture = document.Shapes.InsertPicture(document.CreatePosition(15),
    System.Drawing.Image.FromFile("Documents\\beverages.png"));
myPicture.HorizontalAlignment = ShapeHorizontalAlignment.Center;