If you ever used Microsoft Word Automation in one of your projects, you will know how complex the manipulation of a document can be. Word Automation is a technology that can be used to manipulate Word documents in .NET applications by using the client executable of MS Word.

Documents can be manipulated using a hard to use API called the Word Object Model. In case you are using the Office Open XML SDK to manipulate DOCX files, similar knowledge about the actual document is required in order to properly change or build a document.

In order to do simple tasks such as adding a paragraph to a document, the following code is required:

Word.Application wordApp = new Word.Application();
wordApp.Visible = true;
Word.Document doc = wordApp.Documents.Add();
Word.Range range = doc.Content;
Word.Paragraph paragraph = range.Paragraphs.Add();
paragraph.Range.Text = "Hello World!";

In comparison to those tree-based models, the TX Text Control API is much better structured, easy to learn and more understandable without any document format specific knowledge.

Referring to the above sample, this task can be easily achieved using the TX Text Control API:

TXTextControl.ServerTextControl doc = new TXTextControl.ServerTextControl();
doc.Create();
doc.Selection.Text = "Hello World!";

You can see the difference quite easily: While you need extensive knowlegde about the document structure when using MS Word Automation, you simply use the Selection object in TX Text Control.

In TX Text Control, collections are available for all elements such as tables, images, pages, paragraphs or sections. Let's say you want to insert an image on every page without using headers and footers:

foreach (Page page in textControl1.GetPages())
{
    TXTextControl.Image img = new TXTextControl.Image();
    img.FileName = "tx_text_control_logo.png";

    textControl1.Images.Add(img,
        page.Number,
        new Point(100, 100),
        ImageInsertionMode.AboveTheText);
}

You can easily loop through the collection of pages in order to add a new image to each page. You don't need to use enumerators, but you have access to very easy-to-use collections.

In order to add text at a specific character location, the Selection object can be utilized. You simply create a new Selection object with a start index. In the next scenario, a new formatted text should be inserted at a specific character location:

TXTextControl.Selection sel = new Selection();
sel.Start = 5;

sel.Bold = true;
sel.Text = "New Text";

textControl1.Selection = sel;

There are other collections on top of this concept that can be used to get a specific start index for the Selection. Consider the following situation: You want to insert a new text at the beginning of page 5. The Page object returns the start index through the Start property which then can be used with the Start property of the Selection. The Selection.Start property is 0-based (input position) while the character positions are all 1-based - therefore, 1 must be subtracted from the return value. The following code inserts new text on page 5:

TXTextControl.Selection sel = new Selection();
sel.Start = textControl1.GetPages()[5].Start - 1;
sel.Text = "New Text on Page 5";

textControl1.Selection = sel;

Conclusion: TX Text Control offers a very easy-to-learn API to create and manipulate documents in a very fast and efficient way. Powerful collections and objects can be used instead of complex tree-based object models.

Start today and download a fully featured, 30 day trial version