TX Text Control .NET for Windows Forms

Document Processing

Topic

Most of what a user does with a document in the editor, your code does too: create and load documents, insert and format text, build tables, place images, add headers, fields and form fields, review changes, print and convert. Windows Forms developers who have finished the first tutorials find each of these tasks here in code, with the details from the object model to error handling.

How Document Processing Works

Two classes hold a document, and both have the same programming interface for its content:

TextControlServerTextControl
What it isThe editor control on your formA component without a user interface
Shows the documentYesNo
Used forThe document the user works onDocuments your code builds, converts, merges or prints
ThreadThe UI thread of the formAny thread, one instance per thread

The examples of this section are button handlers in Form1.cs that work on a TextControl named textControl1, and use a ServerTextControl where the user doesn't need to see the document. The code that builds a document works with either class. Two rules apply everywhere:

  • Collections belong to the text part with the input focus. In the TextControl, collections such as Tables, TextFields and Comments contain the elements of the main text, a text frame or a header or footer, depending on where the input position is. TextParts reaches all of them.
  • Positions count from 0 or from 1. The input position and selections start at 0, the Start properties of paragraphs, fields and other elements at 1.

Document Object Model explains both in detail.

Find the Right Page

If you want toRead
Understand how a document is organized in codeDocument Object Model
Start a document, set its page format, combine documentsCreating Documents
Load DOCX, RTF, HTML or PDF files, byte arrays and streamsLoading Documents
Save a document or convert a folder to PDFSaving and Converting Documents
Find, replace and format text, use styles and listsText, Paragraphs, and Stylesheets
Fill tables from data and calculate with formulasTables and Calculations
Place images, text frames and shapesImages, Text Frames, and Shapes
Insert charts and barcodesCharts and Barcodes
Add sections, landscape pages, headers, footers and page numbersSections, Pages, Headers, and Footers
Insert fields, links and bookmarks or mark ranges of textFields and Subtext Parts
Build fillable forms with validationForms and Conditional Instructions
Track changes, add comments, accept and rejectComments and Tracked Changes
Edit XML files with a DTD and a stylesheetXML Processing
Print in code, in the background or in batchesPrinting
Process documents in the background without blocking the formUsing ServerTextControl in Desktop Applications
Catch and report errorsExceptions and Error Handling
Write the rules that validate, enable and fill form fieldsConditional Instructions
Create content controls and read Word form fieldsContent Controls and Word Form Fields

Where to Start

  1. If you haven't yet, follow the tutorials of Document Processing in Getting Started: they create, save and print a first document.
  2. Read Document Object Model, which every other page builds on.
  3. Read Loading Documents and Saving and Converting Documents, and Using ServerTextControl in Desktop Applications if your application processes documents the user doesn't see.
  4. Continue with the page of the element you need, and add Exceptions and Error Handling before your application goes to users.

Filling templates with data is the subject of Mail Merge and Reporting, and PDF options such as PDF/A and passwords are covered in PDF Processing. What users do with the same elements in the editor is described in Document Editor.

Pages in This Section