Document Processing
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,Commentsand similar collections of theTextControlcontain the elements of the main text, a text frame or a header or footer, depending on where the cursor is.TextPartscontains all parts. - Positions count from 0 or from 1. Selections and the input position start at 0; the
Startof paragraphs, fields and other elements starts at 1.
Document Object Model 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 |
| Start a document, set its page format, combine documents | Creating Documents |
| Load files, byte arrays, strings and streams | Loading Documents |
| Save, convert to PDF and control the output | Saving and Converting Documents |
| Find, replace and format text; styles and lists | Text, Paragraphs, and Stylesheets |
| Build tables and formulas | Tables and Calculations |
| Add images, text frames and shapes | Images, Text Frames, and Shapes |
| Add charts and barcodes | Charts and Barcodes |
| Set up sections, headers, footers and page numbers | Sections, Pages, Headers, and Footers |
| Work with fields, links, bookmarks and subtext parts | Fields and Subtext Parts |
| Create forms and validate their values | Forms and Conditional Instructions |
| Record, review and remove comments and changes | Comments and Tracked Changes |
| Edit XML data with a DTD and CSS | XML Processing |
| Print from code and in the background | Printing |
| Keep the window responsive during long work | Using ServerTextControl in Desktop Applications |
| Catch errors and exceptions | Exceptions and Error Handling |
| Validate form values with rules: operators, instruction types, radio button groups | Conditional Instructions |
| Read Word form fields and create content controls with field adapters | Content Controls |
Recommended Order
- Work through Document Processing in Getting Started, if you haven't yet.
- Read Document Object Model: the other pages rely on it.
- Continue with Loading Documents and Saving and Converting Documents.
- When documents are processed outside the editor, read Using ServerTextControl in Desktop Applications, and before shipping, Exceptions and Error Handling.
The same elements from the user's side, with the ribbon and dialog boxes, are covered in Document Editor. Templates filled with data are the subject of Mail Merge and Reporting, and PDF-specific options of PDF Processing.
Pages in This Section
- Document Object Model — text parts, collections, positions and units.
- Creating Documents — new documents, page format and combined documents.
- Loading Documents — load, append and insert, and
LoadSettings. - Saving and Converting Documents — formats, partial saving and
SaveSettings. - Text, Paragraphs, and Stylesheets — text, formatting, styles and lists.
- Tables and Calculations — tables, cells and formulas.
- Images, Text Frames, and Shapes — frames and their positions.
- Charts and Barcodes — charts and barcodes in documents.
- Sections, Pages, Headers, and Footers — page layout and page numbers.
- Fields and Subtext Parts — marked text, links and ranges.
- Forms and Conditional Instructions — fillable forms and their rules.
- Comments and Tracked Changes — review markup.
- XML Processing — XML files with DTD and CSS.
- Printing —
Printoverloads,PrintDocumentand the formatting printer. - Using ServerTextControl in Desktop Applications — background work and threads.
- Exceptions and Error Handling — TX Text Control exceptions and where to catch them.
- Conditional Instructions — rules that validate and change form fields.
- Content Controls — content controls and legacy Word form fields through field adapters.