Products Technologies Demo Docs Blog Support Company

Different Ways to Insert Images

Images can be added to a document from various sources: Physical files, streams or System.Drawing.Images. This article explains how to create images and to add them to a document.

Different Ways to Insert Images

In order to insert an image into a document, an Image object must be created. In the first example, an image is created from a physical file:

TXTextControl.Image image = new TXTextControl.Image("image.png", 4);
textControl1.Images.Add(image, -1);

According to the documentation, it is required to provide the import filter index in the constructor of the Image class. The index can be retrieved using the ImportFilters property. But technically, you can provide any index and TX Text Control is recognizing the image format automatically (but it might take a little longer).

Another way to create an Image object is to provide a System.Drawing.Image in the constructor. In this case, you can create any bitmap image and load it into the Text Control:

System.Drawing.Image sdImage = System.Drawing.Image.FromFile("image.png");

TXTextControl.Image image = new TXTextControl.Image(sdImage);
textControl1.Images.Add(image, -1);

Images from a Stream

In a third implementation, an image can be created from a stream. The MemoryStream must be publicly visible as Text Control is accessing the stream when the image is actually added to the document:

byte[] bytes = System.IO.File.ReadAllBytes("image.png");

MemoryStream ms = new MemoryStream(
  bytes, 0, bytes.Length, writable: false, publiclyVisible: true);


TXTextControl.Image image = new TXTextControl.Image(ms);
textControl1.Images.Add(image, -1);

All of the above samples insert the image at a text position and the image is handled inline like a character. The following insertion modes are available:

  • Inline with text
  • Anchored to a paragraph
  • Fixed on a page

Combine Insertion Modes

The following InsertionModes are supported:

Member Description
AsCharacter The image is inserted in the text as a single character.
DisplaceCompleteLines The image is inserted at a certain geometrical location. The text stops at the top and continues at the bottom of the image.
DisplaceText The image is inserted at a certain geometrical location. The text flows around the image and empty areas at the left and right side are filled.
AboveTheText The image is inserted at a certain geometrical location above the text. This means that the image overwrites the text.
BelowTheText The image is inserted at a certain geometrical location below the text. This means that the text overwrites the image.
MoveWithText The image is connected with a paragraph and moved with the text.
FixedOnPage The image is fixed positioned on a page.

The values of the ImageInsertionMode enumeration can be combined. The following combinations are possible:

  • DisplaceCompleteLines | MoveWithText
  • DisplaceCompleteLines | FixedOnPage
  • DisplaceText | MoveWithText
  • DisplaceText | FixedOnPage
  • AboveTheText | MoveWithText
  • AboveTheText | FixedOnPage
  • BelowTheText | MoveWithText
  • BelowTheText | FixedOnPage
  • AsCharacter

Anchored to Paragraphs

For example, the following code inserts an image that is anchored to the paragraph at the current input position with a location offset of 500 twips in both directions:

TXTextControl.Image image = new TXTextControl.Image("image.png", 4);

textControl1.Images.Add(image, new Point(500,500), -1, 
  TXTextControl.ImageInsertionMode.MoveWithText |
  TXTextControl.ImageInsertionMode.DisplaceText);

The location is given in twips at which the image is to be inserted. This is a location relative to the top left corner either of a page or a paragraph.

Image location

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.Image Class
  • TXTextControl.ImageCollection.Add Method
  • TXTextControl.ImageCollection Class

Related Posts

ASP.NETWindows FormsWPF

TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version

TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETWindows FormsWPF

Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format

Maintaining the integrity and functionality of documents throughout their lifecycle is paramount. TX Text Control provides a robust ecosystem that focuses on preserving documents in their internal…


ActiveXASP.NETWindows Forms

Expert Implementation Services for Legacy System Modernization

We are happy to officially announce our partnership with Quality Bytes, a specialized integration company with extensive experience in modernizing legacy systems with TX Text Control technologies.


ActiveXASP.NETWindows Forms

Service Pack Releases: What's New in TX Text Control 33.0 SP1 and 32.0 SP5

TX Text Control 33.0 Service Pack 1 and TX Text Control 32.0 Service Pack 5 have been released, providing important updates and bug fixes across platforms. These service packs improve the…