# Save as DOCX and PDF

> Save ServerTextControl documents as DOCX and PDF to a file or byte array, return them from an ASP.NET Core controller, and save HTML or plain text.

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

---

Once a document is ready, you save it as DOCX or PDF to a file or a byte array, return it from an ASP.NET Core controller or save it as HTML or plain text. PDF metadata and PDF/A are covered in [Create a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/llms-full.txt).

### Prerequisites

- A console application that references `TXTextControl.TextControl.Core.SDK`, as created in [Create Your First Application](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/first-application/llms-full.txt).
- For the examples that convert a document, a `sample.docx` file in a `Documents` folder that is copied to the output directory, as described in [Load a Document](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/load/llms-full.txt).
- For the controller example, Visual Studio 2026 with the .NET 10 SDK. The section creates the ASP.NET Core application.

### How Saving Works

You save a document with the [ServerTextControl.Save](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/servertextcontrol/save-method/llms-full.txt) method. It always saves the complete document. As with loading, the enumeration you pass depends on where the data goes:

| Target | First parameter | Format parameter |
|---|---|---|
| File path | `string` | [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) |
| File stream | `System.IO.FileStream` | [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) |
| Byte array | `out byte[]` | [BinaryStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/binarystreamtype/enumeration/llms-full.txt) |
| String | `out string` | [StringStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/stringstreamtype/enumeration/llms-full.txt) |

Every overload also accepts a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/savesettings/llms-full.txt) object as an optional third parameter.

The values for DOCX and PDF:

| Format | `StreamType` | `BinaryStreamType` |
|---|---|---|
| DOCX | `WordprocessingML` | `WordprocessingML` |
| PDF | `AdobePDF` | `AdobePDF` |
| PDF/A | `AdobePDFA` | `AdobePDFA` |

### Save to a File

Pass the path of the file and a `StreamType` value. If the file does not exist, it is created. If it exists, its contents are overwritten. The following example creates a document and saves it in both formats:

```csharp
using TXTextControl;

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

    tx.Text = "This document is saved as DOCX and PDF.";

    // Save the document as DOCX
    tx.Save("result.docx", StreamType.WordprocessingML);

    // Save the document as PDF
    tx.Save("result.pdf", StreamType.AdobePDF);
}
```

Converting a document works the same way: load it in one format and save it in another, as [Convert an Existing Document to PDF](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/#convert-an-existing-document-to-pdf) shows for DOCX to PDF.

### Save to a Byte Array

When the document is sent over the network, stored in a database or attached to an email, save it to a byte array instead of a file. Declare the variable and pass it with `out`. `Save` creates the array, so you do not allocate it yourself:

```csharp
using TXTextControl;

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

    tx.Load("Documents/sample.docx", StreamType.WordprocessingML);

    // Save the document as PDF into a byte array
    byte[] pdf;
    tx.Save(out pdf, BinaryStreamType.AdobePDF);

    // Save the document as DOCX into a byte array
    byte[] docx;
    tx.Save(out docx, BinaryStreamType.WordprocessingML);

    Console.WriteLine($"PDF: {pdf.Length} bytes, DOCX: {docx.Length} bytes");
}
```

### Return a Document From an ASP.NET Core Controller

`ServerTextControl` works the same way in an ASP.NET Core application. In a web application, save the document to a byte array and return it with the `File` method of the controller. The content type tells the browser what kind of file it receives, and the file name makes the browser download it.

1. In Visual Studio 2026, create a new project and select **ASP.NET Core Web App (Model-View-Controller)** as the project template. Choose **.NET 10.0 (Long Term Support)** as the **Framework**.
2. Install the `TXTextControl.TextControl.Core.SDK` package as described in [Install the NuGet Package](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/first-application/#install-the-nuget-package).
3. Add the following class as `DocumentController.cs` to the `Controllers` folder:

```csharp
using Microsoft.AspNetCore.Mvc;
using TXTextControl;

public class DocumentController : Controller
{
    public IActionResult Pdf()
    {
        using (ServerTextControl tx = new ServerTextControl())
        {
            tx.Create();
            tx.Text = "This PDF was created in ASP.NET Core.";

            byte[] pdf;
            tx.Save(out pdf, BinaryStreamType.AdobePDF);

            return File(pdf, "application/pdf", "document.pdf");
        }
    }

    public IActionResult Docx()
    {
        using (ServerTextControl tx = new ServerTextControl())
        {
            tx.Create();
            tx.Text = "This DOCX was created in ASP.NET Core.";

            byte[] docx;
            tx.Save(out docx, BinaryStreamType.WordprocessingML);

            return File(docx,
                "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                "document.docx");
        }
    }
}
```

1. Start the application and open `/Document/Pdf` in the browser. With the default route of an ASP.NET Core MVC application, the actions are available at `/Document/Pdf` and `/Document/Docx`, and the browser downloads `document.pdf`.

### Save PDF With Metadata or as PDF/A

A [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/savesettings/llms-full.txt) object, passed as the third parameter of `Save`, adds document metadata such as the title, author and keywords, a password or access permissions, and digital signatures. To create a PDF/A document for long-term archiving, save with `StreamType.AdobePDFA` or `BinaryStreamType.AdobePDFA` instead of `AdobePDF`. [Set Document Properties](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/#set-document-properties) and [Create a PDF/A Document](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/#create-a-pdf-a-document) in Create a PDF show both with code.

### Save Other Formats

The same method saves the other formats listed in [Formats and StreamType Values](https://docs.textcontrol.com/tx-text-control-dotnet-server/overview/file-formats/#formats-and-streamtype-values), except XLSX, which TX Text Control only loads. Text-based formats can be saved to a string. For example, the following line saves the document as HTML:

```csharp
string html;
tx.Save(out html, StringStreamType.HTMLFormat);
```

The next line extracts the text of the document as plain text:

```csharp
string plainText;
tx.Save(out plainText, StringStreamType.PlainText);
```

### Next Steps

- [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/llms-full.txt) — create, modify and sign PDF documents.
- [Digitally Sign a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/sign/llms-full.txt) — add a digital signature when you save a PDF.
- [Simple Mail Merge](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/mail-merge/simple/llms-full.txt) — merge data into a template and save the result as PDF.
- [Document Metadata](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/metadata/llms-full.txt) — read and write PDF metadata.

---

## Nearby

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