Products Technologies Demo Docs Blog Support Company
TX Text Control 34.0 SP1 has been released - Learn more

Using Interactive Features with ServerTextControl

The non-UI ServerTextControl class is used to create documents programmatically and doesn't expose interactive features such as adding or modifying tracked changes. This article shows how to use the TextViewGenerator class to achieve this.

Using Interactive Features with ServerTextControl

The ServerTextControl class implements a non-UI component to create documents programmatically or to connect to the MailMerge engine to generate documents from templates and hierarchical data. These processes doesn't require access to interactive features such as adding tracked changes or to accept and reject them.

For example, the following code can be used to iterate through all tracked changes to get the text and user name:

using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
  tx.Create();
  tx.Load(data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

  foreach(TXTextControl.TrackedChange change in tx.TrackedChanges) {
    Console.WriteLine("Text: {0}, User: {1}", change.Text, change.UserName);
  }
}

But the ServerTextControl doesn't have a UserNames property like the visual document editor to add interactive tracked changes to a document.

Interactive ServerTextControl

Consider a scenario where you want to programmatically accept or reject changes in a non-UI, server-side process. Or, when applying changes to a document programmatically, you want to keep track of those changes. For this purpose, an interactive version of the ServerTextControl is available: The TextViewGenerator class.

This class is inherited from ServerTextControl, but implements user interactive features including event handling. An instance is created very similar to ServerTextControl:

using (TXTextControl.ServerVisualisation.TextViewGenerator tx =
        new TXTextControl.ServerVisualisation.TextViewGenerator()) { 
        tx.Create();
        // ready to use
}

Applying Tracked Changes

The following code is used to create a new instance of TextViewGenerator to set a current user name and to apply two changes (delete and add) to text in the document:

using (TXTextControl.ServerVisualisation.TextViewGenerator tx =
  new TXTextControl.ServerVisualisation.TextViewGenerator()) { 
    tx.Create();

  tx.Selection.Text = "1234567890";

  tx.IsTrackChangesEnabled = true;
  tx.UserNames = new string[] {"qa@textcontrol.com" };
  tx.Select(2, 3);
  tx.Selection.Text = "New Text";
}

This is very helpful to apply modifications from the document viewer that allows users to step through tracked changes and to accept or reject them. The results can then be applied to the actual document programmatically in a server-side non-UI process.

Learn More

A new feature has been rolled out with the latest update of the TX Text Control DocumentViewer that allows users to navigate through tracked changes in order to reject and accept changes in browser and mobile views.

Document Viewer: Processing Tracked Changes

Interactive Events

The TextViewGenerator implements all interactive events similar to the visual versions of TX Text Control including the web document editor. The following code shows how to attach the Changed and TableCreated event:

using (TXTextControl.ServerVisualisation.TextViewGenerator tx =
  new TXTextControl.ServerVisualisation.TextViewGenerator()) { 
    tx.Create();

  tx.Changed += Tx_Changed;
  tx.TableCreated += Tx_TableCreated;

  tx.Selection.Text = "1234567890";
  tx.Tables.Add(5, 5, 13);
}

private void Tx_TableCreated(object sender, TXTextControl.TableEventArgs e) {
  Console.WriteLine("Table added. Id: {0}", e.Table.ID);
}

private void Tx_Changed(object sender, EventArgs e) {
  Console.WriteLine("Content changed");
}
Content changed
Table added. Id: 13
Content changed

Conclusion

In order to apply interactive changes to a document programmatically, the non-UI class TextViewGenerator can be used. This class is completely compatible to ServerTextControl, but exposes all interactive features and event handling.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETWindows FormsWPF

Tracked Changes: Toggle Markup

Tracked changes is also known as red-lining - a way to track changes done by users to a document. Displaying the changes in various colors can be distracting. This demo code shows how to turn the…


ASP.NETWindows FormsWPF

Powerful Extension Methods to Handle Tracked Changes

This article shows how to implement powerful extension methods to remove all tracked changes in all text parts by a given username.


ASP.NETASP.NET CoreMIME

Why Defining MIME Types for PDF/A Attachments Is Essential

The PDF/A standard was created to ensure the long-term reliable archiving of digital documents. An important aspect of the standard involves properly handling embedded files and attachments within…


ASP.NETASP.NET CoreConference

We are Returning to CodeMash 2026 as a Sponsor and Exhibitor

We are excited to announce that we will be returning to CodeMash 2026 as a sponsor and exhibitor. Join us to learn about the latest in .NET development and how our products can help you build…


ASP.NETASP.NET Core

AI-Ready Documents in .NET C#: How Structured Content Unlocks Better…

Most organizations use AI on documents that were never designed for machines. PDFs without tags, inconsistent templates, undescribed images, and disorganized reading orders are still common. This…

Summarize this blog post with:

Share on this blog post on: