# Document Processing

> Work with documents in WPF code-behind: object model, loading and saving, tables, sections, fields, forms, comments, XML, printing and ServerTextControl.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Document Processing
- **1757 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/llms-full.txt

---

After the first tutorials, a WPF application usually needs more than loading and saving: tables filled from data, headers with page numbers, fields, forms, tracked changes, printing and conversions that run while the window stays responsive. Each of these tasks is shown below in the code-behind of a window, together with the object model behind it, one page per element your application works with.

### How Document Processing Works

A document lives either in the WPF `TextControl` that the user sees or in a `ServerTextControl` that has no user interface:

|  | `TXTextControl.WPF.TextControl` | `TXTextControl.ServerTextControl` |
|---|---|---|
| Declared | In XAML, as `WPF:TextControl` | In code, with `new`, `Create` and `using` |
| Shows the document | Yes | No |
| Thread | The UI thread of the window | Any thread, one instance per thread |
| Used for | The document the user edits | Documents your code builds, converts, merges or prints |

Both share the classes that describe the content, such as `Selection`, `Paragraph`, `Table`, `Section` and `TextField`, so the same code builds a document in either. The examples of this section are handlers in *MainWindow.xaml.cs* for a `TextControl` named `textControl1`. Two rules hold throughout:

- **A collection belongs to the text part with the input focus.** `Tables`, `TextFields`, `Comments` and similar collections of the `TextControl` contain the elements of the main text, a text frame or a header or footer, depending on where the cursor is. `TextParts` contains all parts.
- **Positions count from 0 or from 1.** Selections and the input position start at 0; the `Start` of paragraphs, fields and other elements starts at 1.

[Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt) describes both rules and the structure of a document.

### Find the Right Page

| Task | Page |
|---|---|
| Learn how the parts of a document are organized | [Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt) |
| Start a document, set its page format, combine documents | [Creating Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/creating/llms-full.txt) |
| Load files, byte arrays, strings and streams | [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/loading/llms-full.txt) |
| Save, convert to PDF and control the output | [Saving and Converting Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/saving-converting/llms-full.txt) |
| Find, replace and format text; styles and lists | [Text, Paragraphs, and Stylesheets](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/text-paragraphs/llms-full.txt) |
| Build tables and formulas | [Tables and Calculations](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/tables/llms-full.txt) |
| Add images, text frames and shapes | [Images, Text Frames, and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/images-shapes/llms-full.txt) |
| Add charts and barcodes | [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/charts-barcodes/llms-full.txt) |
| Set up sections, headers, footers and page numbers | [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/sections-headers/llms-full.txt) |
| Work with fields, links, bookmarks and subtext parts | [Fields and Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/llms-full.txt) |
| Create forms and validate their values | [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/form-fields/llms-full.txt) |
| Record, review and remove comments and changes | [Comments and Tracked Changes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/comments-changes/llms-full.txt) |
| Edit XML data with a DTD and CSS | [XML Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/xml/llms-full.txt) |
| Print from code and in the background | [Printing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/printing/llms-full.txt) |
| Keep the window responsive during long work | [Using ServerTextControl in Desktop Applications](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/servertextcontrol/llms-full.txt) |
| Catch errors and exceptions | [Exceptions and Error Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/exceptions/llms-full.txt) |
| Validate form values with rules: operators, instruction types, radio button groups | [Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/conditional-instructions/llms-full.txt) |
| Read Word form fields and create content controls with field adapters | [Content Controls](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/llms-full.txt) |

### Recommended Order

1. Work through [Document Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-processing/llms-full.txt) in Getting Started, if you haven't yet.
2. Read [Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt): the other pages rely on it.
3. Continue with [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/loading/llms-full.txt) and [Saving and Converting Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/saving-converting/llms-full.txt).
4. When documents are processed outside the editor, read [Using ServerTextControl in Desktop Applications](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/servertextcontrol/llms-full.txt), and before shipping, [Exceptions and Error Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/exceptions/llms-full.txt).

The same elements from the user's side, with the ribbon and dialog boxes, are covered in [Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/llms-full.txt). Templates filled with data are the subject of [Mail Merge and Reporting](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/llms-full.txt), and PDF-specific options of [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/llms-full.txt).

### Pages in This Section

- [Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt) — text parts, collections, positions and units.
- [Creating Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/creating/llms-full.txt) — new documents, page format and combined documents.
- [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/loading/llms-full.txt) — load, append and insert, and `LoadSettings`.
- [Saving and Converting Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/saving-converting/llms-full.txt) — formats, partial saving and `SaveSettings`.
- [Text, Paragraphs, and Stylesheets](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/text-paragraphs/llms-full.txt) — text, formatting, styles and lists.
- [Tables and Calculations](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/tables/llms-full.txt) — tables, cells and formulas.
- [Images, Text Frames, and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/images-shapes/llms-full.txt) — frames and their positions.
- [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/charts-barcodes/llms-full.txt) — charts and barcodes in documents.
- [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/sections-headers/llms-full.txt) — page layout and page numbers.
- [Fields and Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/llms-full.txt) — marked text, links and ranges.
- [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/form-fields/llms-full.txt) — fillable forms and their rules.
- [Comments and Tracked Changes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/comments-changes/llms-full.txt) — review markup.
- [XML Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/xml/llms-full.txt) — XML files with DTD and CSS.
- [Printing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/printing/llms-full.txt) — `Print` overloads, `PrintDocument` and the formatting printer.
- [Using ServerTextControl in Desktop Applications](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/servertextcontrol/llms-full.txt) — background work and threads.
- [Exceptions and Error Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/exceptions/llms-full.txt) — TX Text Control exceptions and where to catch them.
- [Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/conditional-instructions/llms-full.txt) — rules that validate and change form fields.
- [Content Controls](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/llms-full.txt) — content controls and legacy Word form fields through field adapters.

---

## In This Section

- [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/charts-barcodes/llms-full.txt): Insert Code 128 barcodes with the WPF TXBarcodeControl, validate and caption their text, update or remove them, and see why charts need Windows Forms.
- [Comments and Tracked Changes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/comments-changes/llms-full.txt): Accept or reject tracked changes by author in all WPF text parts, remove every comment and change before a PDF, and compare two documents with track changes.
- [Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/conditional-instructions/llms-full.txt): Validate WPF form fields with conditional instructions from the Form Fields ribbon tab or in C#: the Condition alias, date and regex rules and radio groups.
- [Content Controls](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/llms-full.txt): Load MS Word content controls and legacy form fields into the WPF TextControl, then read, change and create them with FormCheckBox, FormText and field adapters.
- [Creating Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/creating/llms-full.txt): Create documents in a WPF window: clear the TextControl, set page size in 1/96 inch, insert formatted text, combine files, store properties, use IsUndoEnabled.
- [Exceptions and Error Handling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/exceptions/llms-full.txt): Catch FilterException and LicenseLevelException in WPF code-behind, check return values, handle Task.Run errors and use DispatcherUnhandledException.
- [Fields and Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/llms-full.txt): Collect fields of all WPF text parts, read MS Word fields with adapters such as MergeField, IfField and NextIfField, and keep data in subtext parts.
- [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/form-fields/llms-full.txt): Form fields in WPF code: TextFormField, CheckFormField, SelectionFormField and DateFormField values, their events, protection, validation and flattening.
- [Images, Text Frames, and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/images-shapes/llms-full.txt): Add images, text frames and shapes to the WPF TextControl, place them inline, anchored or fixed, and avoid the Image, Point and Size name clashes of WPF.
- [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/loading/llms-full.txt): Load and append documents in the WPF TextControl, filter fields with LoadSettings, read LoadedFile after the Open dialog, open protected PDFs and handle errors.
- [Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt): The document model behind the WPF TextControl: text parts, IFormattedText, frames and sections, why collections follow the input focus, and the 1/96 inch unit.
- [Printing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/printing/llms-full.txt): Print WPF documents without the editor: ServerTextControl with PrintDocument in the background, several files in one job and merged letters with MailMerge.
- [Saving and Converting Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/saving-converting/llms-full.txt): Convert a folder picked with OpenFolderDialog to PDF, save with the Save As dialog, export HTML with CSS, compress PDF images and leave out comments in WPF.
- [Sections, Pages, Headers, and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/sections-headers/llms-full.txt): Add landscape sections, chapter headers, page columns and borders in the WPF TextControl, open Page Setup in code and turn pages into BitmapImage thumbnails.
- [Using ServerTextControl in Desktop Applications](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/servertextcontrol/llms-full.txt): Keep a WPF window responsive with ServerTextControl: create it in code instead of XAML, hand documents to the TextControl as byte arrays and merge templates.
- [Tables and Calculations](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/tables/llms-full.txt): Create and fill tables in a WPF window, format cells and rows, change the table at the input position and add self-updating SUM formulas with number formats.
- [Text, Paragraphs, and Stylesheets](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/text-paragraphs/llms-full.txt): Format characters and paragraphs in the WPF TextControl, replace placeholders in headers and text frames, and define paragraph and inline styles and lists.
- [XML Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/xml/llms-full.txt): Edit XML data in the WPF TextControl: load files with a DTD and CSS, handle XmlInvalid in XAML, change XmlElement objects and save the XML and its styles.

---

## Nearby

- **Previous:** [Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/events/llms-full.txt)
- **Next:** [Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt)
