ServerTextControl
ServerTextControl is the document processing component of TX Text Control .NET Server that you use in code. The sections below describe what it is and what you do with it, where it runs, which packages contain it and which members you use most. A first application with it is built step by step in Getting Started: Document Processing.
What ServerTextControl Is
ServerTextControl is TX Text Control without a user interface: a non-visual component that provides high-level word processing features for server-based applications. The class is TXTextControl.ServerTextControl, and it is derived from System.ComponentModel.Component.
Its word processing functions are available as properties and methods: you insert and format text, add tables and images, and select parts of the text in code. You create an instance, build or load a document, change it, and save the result in the format you need.
ServerTextControl is also the base for other parts of the product. MailMerge uses a ServerTextControl instance to hold the template and the merged document, and documents that users edit in the Document Editor or sign in the Document Viewer can be processed further with ServerTextControl on the server.
What You Do With It
- Create documents from scratch, such as letters, invoices or reports, with formatted text, tables, images, headers and footers.
- Load and convert documents. Load DOCX, RTF, HTML, PDF and other formats, and save them in another format. For example, you convert a DOCX file to PDF by loading it and saving it as PDF.
- Change existing documents by inserting, editing or deleting content, and work with the elements of a document, such as fields, form fields, comments and tracked changes. For example, you can read the tracked changes of a DOCX document and accept or reject them in code.
- Create PDF documents, including PDF/A for long-term archiving, set document metadata, and sign PDF documents digitally with a certificate when you save them.
- Import PDF documents to extract their text or to change them and save them again.
- Merge data into templates with the
MailMergeclass.
ServerTextControl loads from and saves to a file, a file stream, a byte array or a string, so you can return a document from a Web API, store it in a database or attach it to an email without writing a file first.
Where It Runs
Because it needs no user interface, you can use ServerTextControl wherever .NET code runs on a server or in the background:
- ASP.NET Core web applications and Web APIs
- Console applications
- Services and other server-side processes
ServerTextControl is part of both TX Text Control engines, which target .NET 8 or higher, and both contain the class in the TXTextControl namespace, so your code is the same. With the Core package TXTextControl.TextControl.Core.SDK, it runs on Windows and Linux, including Docker containers; with the Classic package TXTextControl.TextControl.ASP.SDK, on Windows only, but with DOC import and export. Core is recommended for new projects, and Core and Classic compares the engines. Both packages are available on the Text Control Private NuGet Feed.
How You Work With It
Every use of ServerTextControl follows the same pattern:
- Create and initialize. Create an instance and call Create before you use any other member. A
usingstatement disposes the instance and releases its resources when the work is done. - Build or load the document. Load replaces the complete contents with a document. New text and tables are inserted at the current input position, like the cursor in a word processor, and the Selection class applies character and paragraph formatting.
- Save the result. Save writes the complete document in the format you pass.
The format enumeration depends on where the data comes from or goes to:
| Source or target | Format enumeration |
|---|---|
File path or FileStream | StreamType |
| Byte array | BinaryStreamType |
| String | StringStreamType |
LoadSettings and SaveSettings pass additional options, for example to import the fields of a Word template, to write PDF metadata or to sign a PDF. Supported File Formats lists the formats you can load and save.
Example
A console application that creates a document and saves it as DOCX and PDF needs only a few lines: create the instance, call Create, set the text and call Save twice with StreamType.WordprocessingML and StreamType.AdobePDF. Write the Code in Create Your First Application shows it, and Use ServerTextControl in ASP.NET Core saves the document to a byte array and returns it from a controller.
Key Members
| Member | Purpose |
|---|---|
| Create | Initializes the resources of a new instance. It must be called before the object is used. |
| Load | Loads a document in a certain format and replaces the complete contents. |
| Append | Loads a document from a file, a byte array or a string and appends it to the existing document. |
| Save | Saves the complete document in the specified format. |
| Text | Gets or sets the text of the document. |
| Selection | Gets or sets the current selection, which is used to insert text and to apply character and paragraph formatting. |
| Tables | The tables of the document. |
| Images | The images in the main text of the document. |
| HeadersAndFooters | The headers and footers of the document. |
| ApplicationFields | Fields such as MS Word merge fields. LoadSettings.ApplicationFieldFormat must be set before loading, otherwise the collection is empty. |
| FormFields | The form fields of the document. |
| Comments | The comments of the document. |
| TrackedChanges | The tracked changes in the active part of the document. |
| SignatureFields | The signature fields in the main text of the document. |
| EntryAssembly | A static property that sets the assembly which licenses ServerTextControl, for example a class library. By default, this is the application's executable assembly. |
The ServerTextControl reference lists all members. License Configuration explains how the license reaches your application.
Next Steps
- Create Your First Application — install the package and create your first DOCX and PDF.
- Document Processing — creating, loading, saving and changing documents in detail.
- PDF Processing — create, import and digitally sign PDF documents.
- MailMerge — merge data into templates with a
ServerTextControl.