Document Processing
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:
TextControl | ServerTextControl | |
|---|---|---|
| What it is | The editor control on your form | A component without a user interface |
| Shows the document | Yes | No |
| Used for | The document the user works on | Documents your code builds, converts, merges or prints |
| Thread | The UI thread of the form | Any 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 asTables,TextFieldsandCommentscontain the elements of the main text, a text frame or a header or footer, depending on where the input position is.TextPartsreaches all of them. - Positions count from 0 or from 1. The input position and selections start at 0, the
Startproperties of paragraphs, fields and other elements at 1.
Document Object Model explains both in detail.
Find the Right Page
| If you want to | Read |
|---|---|
| Understand how a document is organized in code | Document Object Model |
| Start a document, set its page format, combine documents | Creating Documents |
| Load DOCX, RTF, HTML or PDF files, byte arrays and streams | Loading Documents |
| Save a document or convert a folder to PDF | Saving and Converting Documents |
| Find, replace and format text, use styles and lists | Text, Paragraphs, and Stylesheets |
| Fill tables from data and calculate with formulas | Tables and Calculations |
| Place images, text frames and shapes | Images, Text Frames, and Shapes |
| Insert charts and barcodes | Charts and Barcodes |
| Add sections, landscape pages, headers, footers and page numbers | Sections, Pages, Headers, and Footers |
| Insert fields, links and bookmarks or mark ranges of text | Fields and Subtext Parts |
| Build fillable forms with validation | Forms and Conditional Instructions |
| Track changes, add comments, accept and reject | Comments and Tracked Changes |
| Edit XML files with a DTD and a stylesheet | XML Processing |
| Print in code, in the background or in batches | Printing |
| Process documents in the background without blocking the form | Using ServerTextControl in Desktop Applications |
| Catch and report errors | Exceptions and Error Handling |
| Write the rules that validate, enable and fill form fields | Conditional Instructions |
| Create content controls and read Word form fields | Content Controls and Word Form Fields |
Where to Start
- If you haven't yet, follow the tutorials of Document Processing in Getting Started: they create, save and print a first document.
- Read Document Object Model, which every other page builds on.
- Read Loading Documents and Saving and Converting Documents, and Using ServerTextControl in Desktop Applications if your application processes documents the user doesn't see.
- 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
- Document Object Model: the parts of a document, text parts, positions and units.
- Creating Documents: new documents, page format, combining documents and properties.
- Loading Documents: load, append and insert with
LoadSettings. - Saving and Converting Documents: formats, parts of documents and
SaveSettings. - Text, Paragraphs, and Stylesheets: selections, formatting, styles and lists.
- Tables and Calculations: tables from data, cell formatting and formulas.
- Images, Text Frames, and Shapes: frames inline, anchored or fixed on a page.
- Charts and Barcodes: charts and barcodes in documents.
- Sections, Pages, Headers, and Footers: page layout, page numbers and the pages of a document.
- Fields and Subtext Parts: text fields, links, bookmarks, Word fields and subtext parts.
- Forms and Conditional Instructions: form fields, protection and validation rules.
- Comments and Tracked Changes: tracking, comments and the final version.
- XML Processing: XML files with DTD and CSS.
- Printing:
PrintDocument, batch printing and the formatting printer. - Using ServerTextControl in Desktop Applications: background work and moving documents to the editor.
- Exceptions and Error Handling: the exceptions of TX Text Control and where to catch them.
- Conditional Instructions: conditions, instructions and a complete booking form with rules.
- Content Controls and Word Form Fields: the field adapters for content controls, legacy form fields and NEXT fields.