# Document Loading and Conversion

> Load and convert documents faster in Windows Forms: keep the TX Text Control format, reuse one ServerTextControl, LoadImages and PDFImportSettings, PDF last.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Performance > Document Loading and Conversion
- **2416 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/loading-conversion/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/loading-conversion/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/loading-conversion/llms-full.txt

---

Every time a document is loaded from DOCX or saved as PDF, TX Text Control converts it between that format and its own document model. For one document, the user hardly notices; for a folder of files, a document that goes back and forth many times or a form that has to open quickly, the choices below make the difference: the format a document is kept in, how many instances do the work, what is loaded at all and where the conversion runs.

### Where Loading and Saving Take Time

[Load](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/load-method/llms-full.txt) and [Save](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/save-method/llms-full.txt) of the `TextControl` and the same methods of `ServerTextControl` are synchronous: they return when the document is completely read or written. Three things decide how long that takes:

- **The format.** Word, RTF, HTML and PDF are converted by the filters of TX Text Control; the TX Text Control format is the format of the engine itself.
- **The thread.** A call on the UI thread blocks the form until it returns. A `ServerTextControl` on a background thread doesn't.
- **The number of instances.** Each new `ServerTextControl` is created and initialized before it can load anything.

### Keep the TX Text Control Format While a Document Changes

Text Control recommends its own format for every stage in which a document still changes: templates are designed in it, merged without leaving it and edited and reviewed in it. It needs no parsing or conversion when it's loaded and saved, it is a compact binary format that is smaller than DOCX, and it keeps every feature of TX Text Control. Conversion to PDF or DOCX happens once, when the document is final. Text Control publishes no measurements for this recommendation; the blog article [Document Lifecycle Optimization: Leveraging TX Text Control's Internal Format](https://www.textcontrol.com/blog/2025/05/16/document-lifecycle-optimization-leveraging-tx-text-controls-internal-format/) describes the workflow.

In a Windows Forms application, the following handlers keep a draft in the TX Text Control format and create the PDF file at the end:

```csharp
using System;
using TXTextControl;

private void saveDraftButton_Click(object sender, EventArgs e)
{
    // No conversion: the format of the engine itself
    textControl1.Save("contract.tx", StreamType.InternalUnicodeFormat);
}

private void openDraftButton_Click(object sender, EventArgs e)
{
    textControl1.Load("contract.tx", StreamType.InternalUnicodeFormat);
}

private void publishButton_Click(object sender, EventArgs e)
{
    // Convert once, when the document is final
    textControl1.Save("contract.pdf", StreamType.AdobePDF);
}
```

[StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) `InternalUnicodeFormat` is the TX Text Control format for files; [BinaryStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/binarystreamtype/enumeration/llms-full.txt) `InternalUnicodeFormat` is the same format in a byte array. Documents that move between the editor and a `ServerTextControl` or a database travel best in this form, as [Using ServerTextControl in Desktop Applications](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/servertextcontrol/#move-documents-between-the-editor-and-servertextcontrol) shows.

### Use One Instance for a Batch

A `ServerTextControl` can load one document after another: each [Load](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/load-method/llms-full.txt) replaces the previous document. Create it once for a batch instead of once per file. In Text Control's text replacement benchmark, a batch processed this way took less than half the time per document of a single file; [Replace Text in Many Large Files](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/large-documents/#replace-text-in-many-large-files) shows the code, the numbers and the conditions of the test.

On a background thread, one instance converts a folder without blocking the form, as [Work in the Background](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/servertextcontrol/#work-in-the-background) shows. Several threads can each convert a part of the batch with an instance of their own, as [Convert Many Files With Progress and Cancel](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/threading/#convert-many-files-with-progress-and-cancel) shows; they may wait for each other inside TX Text Control, so measure whether more threads help.

### Load Only What the Task Needs

[LoadSettings](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/loadsettings/llms-full.txt) decides what a document brings into TX Text Control. When your code needs the text of documents and not their layout, for example to fill a search index, leave out what the task doesn't use:

```csharp
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using TXTextControl;

private async void indexButton_Click(object sender, EventArgs e)
{
    Dictionary<string, string> index = new Dictionary<string, string>();

    await Task.Run(() =>
    {
        using (ServerTextControl tx = new ServerTextControl())
        {
            tx.Create();

            LoadSettings wordSettings = new LoadSettings { LoadImages = false };
            LoadSettings pdfSettings = new LoadSettings { PDFImportSettings = PDFImportSettings.GenerateLines };

            foreach (string file in Directory.GetFiles("Documents"))
            {
                string extension = Path.GetExtension(file).ToLowerInvariant();

                if (extension == ".docx")
                {
                    tx.Load(file, StreamType.WordprocessingML, wordSettings);
                }
                else if (extension == ".pdf")
                {
                    tx.Load(file, StreamType.AdobePDF, pdfSettings);
                }
                else
                {
                    continue;
                }

                index[file] = tx.Text;
            }
        }
    });

    MessageBox.Show(this, $"{index.Count} documents indexed.");
}
```

The code works as follows:

- [LoadImages](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/loadsettings/loadimages-property/llms-full.txt) set to `false` leaves the images out; each one is shown as a rectangle with the image's name instead. The default is `true`.
- [PDFImportSettings](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/loadsettings/pdfimportsettings-property/llms-full.txt) with the value `GenerateLines` imports the text of a PDF file only and discards images and paragraph formatting, which the reference recommends for searching PDF files. The default, `GenerateTextFrames`, rebuilds tables, images and text frames.
- [Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/text-property/llms-full.txt) returns the text of the loaded document.

Other settings leave out hypertext links (`LoadHypertextLinks`) or the background color of the document (`LoadDocumentBackColor`). [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/loading/#control-the-import-with-loadsettings) lists them all.

### Convert at the End, in the Background

- **Save PDF once.** A PDF file that is created before the content is final has to be created again. Keep the document in the TX Text Control format until then.
- **Convert off the UI thread.** Saving a long document as PDF from the editor blocks the form. Copy the document into a byte array and let a `ServerTextControl` create the PDF in the background, as [Save the Editor's Document in the Background](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/threading/#save-the-editor-s-document-in-the-background) shows.
- **Compress images.** Images take up most of the size of many PDF files; [Keep PDF Output Small](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/large-documents/#keep-pdf-output-small) shows what compression changes.

### Next Steps

- [Loading Documents](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/loading/llms-full.txt) — all ways to load documents and the settings of `LoadSettings`.
- [Saving and Converting Documents](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/saving-converting/llms-full.txt) — the formats `Save` writes.
- [UI Threading and Background Operations](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/threading/llms-full.txt) — convert without blocking the form.
- [Performance Best Practices](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/best-practices/llms-full.txt) — all measures at a glance.

---

## Nearby

- **Previous:** [Memory Usage and Resource Disposal](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/memory-usage/llms-full.txt)
- **Next:** [Mail Merge Performance](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/performance/mail-merge/llms-full.txt)
