# Save as DOCX and PDF

> Convert documents in Windows Forms: export the TextControl document as DOCX and PDF, convert DOC files with ServerTextControl, save byte arrays and PDF/A.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Getting Started > Document Processing > Save as DOCX and PDF
- **2093 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-processing/save-docx-pdf/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-processing/save-docx-pdf/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-processing/save-docx-pdf/llms-full.txt

---

Converting a document with TX Text Control takes two calls: load it in one format and save it in another. In a Windows Forms application, the document comes either from the editor, where the user wrote it, or from a file that the user never sees. Each case below is a button handler: exporting the editor's document as DOCX and PDF, converting a Word file in the background, saving to byte arrays and creating a PDF/A copy.

### Prerequisites

- The application from [Create Your First Windows Forms Application](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-editor/first-application/llms-full.txt), with a `TextControl` named `textControl1` on `Form1`.
- For each section, a `Button` on the form. Double-click it in the designer to create its `Click` handler.
- The Professional or Enterprise edition for DOC, DOCX and PDF, and the Enterprise edition for PDF/A. See [Editions and Feature Availability](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/overview/editions/llms-full.txt).

*Form1.cs* needs these `using` directives:

```csharp
using System.IO;
using TXTextControl;
```

### Export the Editor's Document

[Save](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/save-method/llms-full.txt) always writes the complete document, in the format you pass. Two calls save it as DOCX and as PDF:

```csharp
private void exportButton_Click(object sender, EventArgs e)
{
    string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

    // Save the complete document in both formats
    textControl1.Save(Path.Combine(folder, "document.docx"), StreamType.WordprocessingML);
    textControl1.Save(Path.Combine(folder, "document.pdf"), StreamType.AdobePDF);

    MessageBox.Show("Saved document.docx and document.pdf in " + folder);
}
```

`StreamType.WordprocessingML` is the DOCX format and `StreamType.AdobePDF` the PDF format. An existing file is overwritten. To let the user choose the file name and to add a title or a password to the PDF, see [Create a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/pdf/create/llms-full.txt).

### Convert a File Without the Editor

A [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/llms-full.txt) converts documents without touching the one in the editor. The following handler lets the user pick a Word 97-2003 document and saves it as DOCX and PDF next to the original:

```csharp
private void convertButton_Click(object sender, EventArgs e)
{
    using (OpenFileDialog dialog = new OpenFileDialog())
    {
        dialog.Filter = "Word 97-2003 documents (*.doc)|*.doc";

        if (dialog.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        using (ServerTextControl tx = new ServerTextControl())
        {
            // Initialize the new instance before using it
            tx.Create();

            tx.Load(dialog.FileName, StreamType.MSWord);

            // Save next to the source file, with the same name
            tx.Save(Path.ChangeExtension(dialog.FileName, ".docx"), StreamType.WordprocessingML);
            tx.Save(Path.ChangeExtension(dialog.FileName, ".pdf"), StreamType.AdobePDF);
        }
    }
}
```

The code works as follows:

- [Create](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/create-method/llms-full.txt) initializes the `ServerTextControl`, and the `using` statement disposes it when the conversion is done.
- [Load](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/load-method/llms-full.txt) reads the file. `StreamType.MSWord` is the binary Word format, DOC.
- [ServerTextControl.Save](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/save-method/llms-full.txt) writes it twice, once in each format.

The same pattern converts any format TX Text Control loads into any format it saves. [Supported File Formats](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/overview/file-formats/llms-full.txt) lists them.

### Save to Byte Arrays

A document that goes into a database or an email attachment does not need a file: with a [BinaryStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/binarystreamtype/enumeration/llms-full.txt) such as `WordprocessingML` or `AdobePDF`, `Save` writes it to a byte array. [Load and Save Without a Dialog Box](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-editor/load-save/#load-and-save-without-a-dialog-box) shows the code.

### Create a PDF/A Copy in the Background

To save the editor's document in another format without changing the editor's settings, hand a copy to a `ServerTextControl`. The following handler creates a PDF/A document, the format for long-term archiving:

```csharp
private void archiveButton_Click(object sender, EventArgs e)
{
    // Copy the editor's document in the TX Text Control format
    byte[] document;
    textControl1.Save(out document, BinaryStreamType.InternalUnicodeFormat);

    using (ServerTextControl tx = new ServerTextControl())
    {
        tx.Create();

        // PDF/A embeds its fonts: use only fonts that can be embedded
        tx.FontSettings.EmbeddableFontsOnly = true;

        tx.Load(document, BinaryStreamType.InternalUnicodeFormat);
        tx.Save("archive.pdf", StreamType.AdobePDFA,
            new SaveSettings() { DocumentTitle = "Archived Document" });
    }
}
```

The code works as follows:

- `BinaryStreamType.InternalUnicodeFormat` is the TX Text Control format. The copy in the `ServerTextControl` is the same document as in the editor.
- `EmbeddableFontsOnly` and `StreamType.AdobePDFA` are set on the copy, so the editor keeps its fonts and settings. What they do is explained in [Create a PDF/A Document](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/pdf/create/#create-a-pdf-a-document).
- [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/savesettings/llms-full.txt) adds the title to the document.

### Next Steps

- [Print a Document](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-processing/print/llms-full.txt): print with or without the editor.
- [Create a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/pdf/create/llms-full.txt): document properties, the Save As dialog, passwords and permissions.
- [Saving and Converting Documents](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-processing/saving-converting/llms-full.txt): all save and conversion options in detail.
- [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/overview/components/servertextcontrol/llms-full.txt): when a desktop application uses the component without a user interface.

---

## Nearby

- **Previous:** [Create a Document Programmatically](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-processing/create/llms-full.txt)
- **Next:** [Print a Document](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-processing/print/llms-full.txt)
