# Create a PDF

> Save a WPF TextControl document as PDF with SaveSettings: document properties, a Save As dialog, PDF/A from a ServerTextControl copy and passwords.

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

---

Saving the document of a WPF `TextControl` as PDF takes a single call of `Save` with the PDF format. What else the file carries, from its title and author to passwords, permissions and PDF/A conformance for archiving, is set in a `SaveSettings` object. Working in the editor window of your first WPF application, the following sections create each kind of PDF from a button and open the result in the PDF reader of Windows.

### Prerequisites

- The application from [Create Your First WPF Application](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/first-application/llms-full.txt), with a `TextControl` named `textControl1` in *MainWindow.xaml*.
- The Professional or Enterprise edition. PDF/A requires the Enterprise edition. See [Editions and Feature Availability](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/editions/llms-full.txt).

For each section, add a button to the `DockPanel` of *MainWindow.xaml*, before the `TextControl` element, and name its `Click` handler after the button:

```xml
<Button x:Name="createPdfButton" DockPanel.Dock="Top" Content="Create PDF"
        Click="createPdfButton_Click" />
```

The handlers go into *MainWindow.xaml.cs*, which needs these `using` directives:

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

### Save the Document as PDF

The following handler saves the document of `textControl1` as *report.pdf* in the user's *Documents* folder, with a few document properties, and opens the file:

```csharp
private void createPdfButton_Click(object sender, RoutedEventArgs e)
{
    SaveSettings saveSettings = new SaveSettings()
    {
        Author = "Tim Typer",
        DocumentTitle = "Quarterly Report",
        DocumentSubject = "Finance",
        DocumentKeywords = new string[] { "report", "Q2", "finance" },
        CreatorApplication = "My WPF Application",
        CreationDate = DateTime.Now,
        LastModificationDate = DateTime.Now
    };

    string path = System.IO.Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
        "report.pdf");

    textControl1.Save(path, StreamType.AdobePDF, saveSettings);

    // Open the PDF in the default PDF reader
    Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
}
```

The code works as follows:

- [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) collects the options of one save. [Author](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/author-property/llms-full.txt), [DocumentTitle](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/documenttitle-property/llms-full.txt), [DocumentSubject](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/documentsubject-property/llms-full.txt), [DocumentKeywords](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/documentkeywords-property/llms-full.txt), [CreatorApplication](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/creatorapplication-property/llms-full.txt), [CreationDate](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/creationdate-property/llms-full.txt) and [LastModificationDate](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/lastmodificationdate-property/llms-full.txt) become the document properties of the PDF.
- [Save](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/save-method/llms-full.txt) writes the complete document. `StreamType.AdobePDF` selects PDF, and a file of the same name is overwritten.
- `Process.Start` with `UseShellExecute` set to `true` opens the file in the program that Windows associates with PDF files.

Run the application, type a few lines and click **Create PDF**. The PDF reader opens *report.pdf* with your text.

Its document properties, which PDF readers show in their **Document Properties** dialog box, contain the title, author, subject and keywords of the `SaveSettings`:

![The Document Properties dialog box of Adobe Acrobat for a PDF created with TX Text Control, showing its title, author, subject, keywords, creation and modification dates and the application.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/pdf-document-properties.6bed9dcb.webp)

### Let the User Choose the File

Called with `StreamType.AdobePDF`, a `SaveSettings` object and no file name, `Save` opens a **Save As** dialog with the PDF file filter, and `SaveSettings.SavedFile` then holds the path the user chose. [Load and Save Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/load-save/#write-the-commands) shows this overload and its dialog result. Another overload takes [SaveSettings.DialogSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/dialogsettings-enumeration/llms-full.txt) and adds options to the dialog.

### Create a PDF/A Document

PDF/A is the standard for long-term archiving, and `StreamType.AdobePDFA` saves a document as PDF/A-3a. Because a PDF/A file embeds its fonts, the document may use only fonts whose license allows embedding:

```csharp
private void createPdfAButton_Click(object sender, RoutedEventArgs e)
{
    // Use only fonts that can be embedded in the PDF
    textControl1.FontSettings.EmbeddableFontsOnly = true;

    textControl1.Save("archive.pdf", StreamType.AdobePDFA);
}
```

[FontSettings.EmbeddableFontsOnly](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/fontsettings/embeddablefontsonly-property/llms-full.txt) restricts the document to embeddable fonts and must be `true` before a document is saved as PDF/A. Its default is `false`, and the setting stays in effect for the editor after the save.

To leave the settings of the editor unchanged, create the PDF/A file from a copy of its document in a [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt):

```csharp
private void archiveButton_Click(object sender, RoutedEventArgs e)
{
    // Take a copy of 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 all fonts of the document
        tx.FontSettings.EmbeddableFontsOnly = true;

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

`BinaryStreamType.InternalUnicodeFormat` is the format of TX Text Control itself, so the copy loses nothing of the editor's document. [PDF/A](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/pdf-a/llms-full.txt) covers the format in detail.

### Protect the PDF With Passwords

A PDF can have two passwords. The user password must be entered to open the document. The master password, also called owner password, protects the permissions, such as printing or copying text:

```csharp
private void protectedPdfButton_Click(object sender, RoutedEventArgs e)
{
    SaveSettings saveSettings = new SaveSettings()
    {
        UserPassword = "user1234",
        MasterPassword = "owner1234",
        DocumentAccessPermissions = DocumentAccessPermissions.AllowLowLevelPrinting |
                                    DocumentAccessPermissions.AllowExtractContents
    };

    textControl1.Save("protected.pdf", StreamType.AdobePDF, saveSettings);
}
```

- [UserPassword](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsavesettingsbase/userpassword-property/llms-full.txt) and [MasterPassword](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsavesettingsbase/masterpassword-property/llms-full.txt) set the two passwords.
- [DocumentAccessPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/documentaccesspermissions-property/llms-full.txt) lists what users may do without the master password, here printing and copying content. Combine the values with `|`. The permissions take effect only when a master password is set.

When the file is opened, the PDF reader asks for the user password:

![The Password dialog box of a PDF reader, stating that the file is protected and asking for the Document Open Password.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/pdf-open-password-prompt.f829ccbf.webp)

PDF readers enforce the permissions, but other programs can ignore them. [Passwords and Access Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/passwords/llms-full.txt) explains what they protect.

### Create a PDF Without the Editor

For a PDF of a document that the user doesn't see, use a `ServerTextControl`, as in the example above. It has the same `Load` and `Save` methods and takes the same `SaveSettings`; [Save as DOCX and PDF](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-processing/save-docx-pdf/#convert-a-file-without-the-editor) converts files with it.

### Next Steps

- [Create a PDF Form](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/pdf/form/llms-full.txt): add fields to the PDF that users fill out.
- [Digitally Sign a PDF](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/pdf/sign/llms-full.txt): sign the PDF with a certificate.
- [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/llms-full.txt): PDF creation, import, fonts, attachments and metadata in detail.
- The blog article [PDF Security Explained: Passwords, Permissions, Encryption, and Digital Signatures in C# .NET](https://www.textcontrol.com/blog/2026/06/08/pdf-security-explained-passwords-permissions-encryption-and-digital-signatures-in-csharp-dotnet/): what passwords, permissions and signatures protect.

---

## Nearby

- **Previous:** [PDF Processing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/pdf/llms-full.txt)
- **Next:** [Create a PDF Form](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/pdf/form/llms-full.txt)
