# Create a PDF

> Create a PDF or PDF/A with ServerTextControl: save to a file or byte array, convert DOCX, set document properties and return the PDF from ASP.NET Core.

- **Product:** TX Text Control .NET Server
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET Server > Getting Started > PDF Processing > Create a PDF
- **2231 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/create/llms-full.txt

---

Creating PDF documents with `ServerTextControl` takes a .NET console application and a few steps: you save a new document as PDF, convert an existing DOCX file, write the PDF to a byte array, create PDF/A and set document properties. Finally, you return a PDF from an ASP.NET Core controller.

### Prerequisites

- A TX Text Control .NET Server license and access to the [Text Control Private NuGet Feed](https://docs.textcontrol.com/tx-text-control-dotnet-server/installation/nuget/private-feed/llms-full.txt).
- .NET 8 or higher. The steps were written with Visual Studio 2026 and .NET 10.
- Basic knowledge of how `ServerTextControl` is used. [Create Your First Application](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/first-application/llms-full.txt) walks you through it.

### Create the Project

1. In Visual Studio, create a new project with the **Console App** template and choose **.NET 10** as the framework.
2. Install the Core package from the Text Control Private NuGet Feed, either with the NuGet Package Manager or from the project folder:

```bash
dotnet add package TXTextControl.TextControl.Core.SDK
```

The Core package runs on Windows and Linux and is recommended for new projects. If your application runs on Windows only, you can use `TXTextControl.TextControl.ASP.SDK` (Classic) instead. The code on this page is the same for both packages.

### Create a Document and Save It as PDF

Replace the content of *Program.cs* with the following code. It creates an empty document, inserts a formatted line of text and saves the document as PDF:

```csharp
using TXTextControl;

using (ServerTextControl tx = new ServerTextControl())
{
    // Create must be called before the instance is used
    tx.Create();

    // Insert formatted text at the beginning of the document
    Selection selection = new Selection(0, 0);
    selection.Text = "Hello, PDF!";
    selection.FontName = "Arial";
    selection.FontSize = 480; // in twips: 480 twips = 24 pt
    selection.Bold = true;
    tx.Selection = selection;

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

Run the application. The file *result.pdf* is created in the working directory of the application: the project folder with `dotnet run`, or the build output folder (for example *bin/Debug/net10.0*) when you start it from Visual Studio. If the file already exists, it is overwritten.

`ServerTextControl` implements `IDisposable`, so the `using` statement releases its resources when the work is done.

### Convert an Existing Document to PDF

To convert a document, load it with the matching `StreamType` and save it as PDF. Add a DOCX file named *sample.docx* to the project and set its **Copy to Output Directory** property to **Copy always**, then use this code:

```csharp
using TXTextControl;

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

    // Load the Word document
    tx.Load("sample.docx", StreamType.WordprocessingML);

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

Other formats work the same way, for example `StreamType.RichTextFormat` for RTF and `StreamType.HTMLFormat` for HTML. The Core package does not support the legacy Word binary format (DOC, `StreamType.MSWord`). See [Load a Document](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/load/llms-full.txt) for more about loading documents, and the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) enumeration for all formats.

### Save the PDF to a Byte Array

In web applications and services, you usually keep the PDF in memory instead of writing a file, for example to send it to a browser or store it in a database. Pass an `out byte[]` variable and `BinaryStreamType.AdobePDF` to `Save`, as [Save to a Byte Array](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/save-docx-pdf/#save-to-a-byte-array) shows:

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

### Create a PDF/A Document

PDF/A is the ISO standard for long-term archiving. To create PDF/A, save the document with `StreamType.AdobePDFA` (or `BinaryStreamType.AdobePDFA` for a byte array). There is no separate PDF/A option in `SaveSettings`: the stream type selects the format.

```csharp
using TXTextControl;

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

    // Allow only fonts that can be embedded in the PDF/A file
    tx.FontSettings.EmbeddableFontsOnly = true;

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

    // Save the document as PDF/A
    tx.Save("sample-archive.pdf", StreamType.AdobePDFA);
}
```

Since version 34.0, TX Text Control writes PDF/A-3a documents, which include the tagged document structure used by assistive technologies. PDF/A embeds all fonts and allows no passwords and no JavaScript; [The Rules of PDF/A](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/pdf-a/#the-rules-of-pdf-a) lists what the standard changes in your document. If your PDF must also conform to PDF/UA, [PDF/UA](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/pdf-ua/llms-full.txt) explains the requirements.

### Set Document Properties

PDF readers show the author, title, subject and keywords of a document, and search tools use them to index files. Set them with a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/savesettings/llms-full.txt) object and pass it to `Save`:

```csharp
using TXTextControl;

using (ServerTextControl tx = new ServerTextControl())
{
    tx.Create();
    tx.Text = "Quarterly report";

    SaveSettings saveSettings = new SaveSettings()
    {
        Author = "Tim Typer",
        DocumentTitle = "Quarterly Report",
        DocumentSubject = "Finance",
        DocumentKeywords = new string[] { "report", "Q2", "finance" },
        CreatorApplication = "My Application",
        CreationDate = DateTime.Now,
        LastModificationDate = DateTime.Now
    };

    tx.Save("report.pdf", StreamType.AdobePDF, saveSettings);
}
```

Open the PDF in Adobe Acrobat Reader and look at the document properties to see the values. [Document Metadata](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/metadata/#where-metadata-lives) lists all metadata properties and how they relate to the document settings.

`SaveSettings` also protects a PDF with a password and access permissions, as [Protect a PDF With Passwords and Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/creation/#protect-a-pdf-with-passwords-and-permissions) describes.

### Return the PDF From an ASP.NET Core Controller

In an ASP.NET Core application, create the PDF in memory and return the byte array with the `File` method of a controller and the content type `application/pdf`. [Return a Document from an ASP.NET Core Controller](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-processing/save-docx-pdf/#return-a-document-from-an-asp-net-core-controller) creates the project and the controller.

### Next Steps

- [Load and Modify a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/load-modify/llms-full.txt): import an existing PDF, read its content and save it again.
- [Digitally Sign a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/sign/llms-full.txt): add a certificate-based signature when you save the PDF.
- [PDF/A](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/pdf-a/llms-full.txt): more about archiving with PDF/A.
- [Document Metadata](https://docs.textcontrol.com/tx-text-control-dotnet-server/pdf/metadata/llms-full.txt): write and read PDF metadata.

---

## Nearby

- **Previous:** [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/llms-full.txt)
- **Next:** [Load and Modify a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/pdf/load-modify/llms-full.txt)
