# Document Viewer: Save the Values of Form Fields in Documents

> The TX Text Control Document Viewer is used to allow users to fill in form fields in documents. This article explains how to save a document with the values of the filled in form fields.

- **Author:** Bjoern Meyer
- **Published:** 2023-12-19
- **Modified:** 2026-07-17
- **Description:** The TX Text Control Document Viewer is used to allow users to fill in form fields in documents. This article explains how to save a document with the values of the filled in form fields.
- **3 min read** (507 words)
- **Tags:**
  - ASP.NET
  - ServerTextControl
  - PDF
  - Form Fields
- **Web URL:** https://www.textcontrol.com/blog/2023/12/19/document-viewer-save-the-values-of-form-fields-in-documents/
- **LLMs URL:** https://www.textcontrol.com/blog/2023/12/19/document-viewer-save-the-values-of-form-fields-in-documents/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2023/12/19/document-viewer-save-the-values-of-form-fields-in-documents/llms-full.txt

---

As of <a href="">version 32.0.2</a>, it is possible to save documents and thus to merge the values of the form fields that have been filled in. Users can fill in form fields when documents with form fields are deployed through the Document Viewer.

![Completing forms with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/12/19/c/assets/forms.webp "Completing forms with TX Text Control")

### Export Values Only

A JavaScript function is available for the export of the form field values in the form of a JSON object.

```
var formFieldValues = TXDocumentViewer.forms.getValues()
```

All of the values in the form fields will be exported as shown in the following JSON string:

```
[
    {
        "name": "insurance_check",
        "type": "checkbox",
        "value": true
    },
    {
        "name": "insurance_name",
        "type": "selection",
        "value": "Health Providers"
    },
    {
        "name": "insurance_date",
        "type": "date",
        "value": "2023-10-18"
    },
    {
        "name": "insurance_state",
        "type": "selection",
        "value": "North Carolina"
    },
    {
        "name": "notes",
        "type": "text",
        "value": "Additional notes"
    }
]
```

### Save Document

As of version 32.0.2, the *saveDocument* method can be used to save the document in a supported format, including the merged form field values.

```
const saveSettings = { mergeFormFields: true, embedAnnotations: false };
const result = await TXDocumentViewer.saveDocument(
    TXDocumentViewer.StreamType.InternalUnicodeFormat,
    saveSettings);
```

This returns a *DownloadDocumentResult* object with asynchronous functions to retrieve the document as a base64-encoded string or as an *ArrayBuffer*. The base64-encoded string is then retrieved using the following code.

```
const base64 = await result.base64();
```

### Sending the Document to a Web API

The following JavaScript code shows how to save the document and send it to a Web API endpoint called *receiveDocument*.

```
async function saveDocument() {
    try {
        const saveSettings = { mergeFormFields: true, embedAnnotations: false };
        const result = await TXDocumentViewer.saveDocument(
            TXDocumentViewer.StreamType.InternalUnicodeFormat,
            saveSettings);

        const base64 = await result.base64();

        const data = { document: base64 };
        const { success, error } = await saveDocumentAjax(data);

        if (success) {
            alert("Document saved.");
        } else {
            alert("Error saving document.");
        }
    } catch (error) {
        console.error("An error occurred:", error);
    }
}

async function saveDocumentAjax(data) {
    return new Promise((resolve) => {
        $.ajax({
            type: "POST",
            url: "/Home/receiveDocument",
            data: data,
            success: (data) => resolve({ success: true, data }),
            error: (xhr, ajaxOptions, thrownError) => resolve({ success: false, error: thrownError }),
        });
    });
}
```

The Web API method then loads the document into a ServerTextControl to save it as a PDF.

```
[HttpPost]
public IActionResult ReceiveDocument(string document)
{
	using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
	{
		tx.Create();
		tx.Load(Convert.FromBase64String(document), TXTextControl.BinaryStreamType.InternalUnicodeFormat);
		tx.Save("document.pdf", TXTextControl.StreamType.AdobePDF);
	}

	return Ok();
}
```

### Processing PDF Form Fields

Processing form fields in PDF documents when loaded by PDF.js is a special case. When a PDF document is loaded into the Document Viewer, form fields can be filled in. The document can then be saved back to PDF with the merged form field values using the saveDocument method.

Based on the example above, the following code would save the PDF document and send it to a Web API endpoint.

```
const result = await TXDocumentViewer.saveDocument(
    TXDocumentViewer.StreamType.AdobePDF,
    saveSettings);
```

The document is retrieved server-side and physically saved as PDF.

```
[HttpPost]
public IActionResult ReceiveDocument(string document)
{
	// convert string to byte array and save as file
	System.IO.File.WriteAllBytes("document.pdf", Convert.FromBase64String(document));

	return Ok();
}
```

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Document Viewer: Save the Values of Form Fields in Documents](https://www.textcontrol.com/blog/2023/10/19/document-viewer-save-the-values-of-form-fields-in-documents/llms.txt)
- [Create Fillable PDF Forms in .NET C#](https://www.textcontrol.com/blog/2024/11/12/create-fillable-pdf-forms-in-net-c-sharp/llms.txt)
- [Sign Documents with a Self-Signed Digital ID From Adobe Acrobat Reader in .NET C#](https://www.textcontrol.com/blog/2024/08/12/sign-documents-with-a-self-signed-digital-id-from-adobe-acrobat-reader-in-net-c-sharp/llms.txt)
- [Programmatically Convert MS Word DOCX Documents to PDF in .NET C#](https://www.textcontrol.com/blog/2024/08/09/programmatically-convert-ms-word-docx-documents-to-pdf-in-net-c-sharp/llms.txt)
- [Extension Method: Flatten Forms Fields in PDF Documents using .NET C#](https://www.textcontrol.com/blog/2024/07/17/flatten-forms-fields-in-pdf-documents-using-net-c-sharp/llms.txt)
- [Chat PDF - A Generative AI Application for PDF Documents using TX Text Control and OpenAI Functions in C#](https://www.textcontrol.com/blog/2024/02/23/ask-pdf-a-generative-ai-application-for-pdf-documents-using-tx-text-control-and-openai-functions-in-c-sharp/llms.txt)
- [Store Documents as PDF/A using C# - A Future-Proof Archiving Format](https://www.textcontrol.com/blog/2023/10/24/store-documents-as-pdfaa-using-csharp-a-futureproof-archiving-format/llms.txt)
- [Convert HTML to PDF in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/23/convert-html-to-pdf-in-aspnet-core-csharp/llms.txt)
- [Generate PDF Documents from MS Word DOCX Templates in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/20/generate-pdf-documents-from-ms-word-docx-templates-in-aspnet-core-csharp/llms.txt)
- [How to Load and View PDF Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/20/how-to-load-and-view-pdf-documents-in-aspnet-core-csharp/llms.txt)
- [How to Create and Deploy PDF Forms in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/17/how-to-create-and-deploy-pdf-forms-in-aspnet-core-csharp/llms.txt)
- [Create, Pre-Select, Flatten and Extract PDF Form Fields using C#](https://www.textcontrol.com/blog/2023/08/14/create-preselect-flatten-and-extract-pdf-form-fields-using-csharp/llms.txt)
- [Healthcare Use Case: Digital Forms Workflow with Electronic Signatures](https://www.textcontrol.com/blog/2023/03/15/healthcare-use-case-digital-forms-workflow-with-electronic-signatures/llms.txt)
- [AI Natural Language Document Generation with MCP and TX Text Control .NET](https://www.textcontrol.com/blog/2026/07/16/ai-natural-language-document-generation-with-mcp-server-and-tx-text-control-dotnet/llms.txt)
- [C# Document Generation: A Developer's Guide for .NET](https://www.textcontrol.com/blog/2026/07/08/csharp-document-generation-developer-guide-for-dotnet/llms.txt)
- [Validating PDF/UA Documents in .NET C#: A Practical Guide](https://www.textcontrol.com/blog/2026/07/06/validating-pdf-ua-documents-in-dotnet-csharp/llms.txt)
- [Automatically Mapping TX Text Control Form Fields to JSON Data in .NET C#](https://www.textcontrol.com/blog/2026/06/03/automatically-mapping-tx-text-control-form-fields-to-json-data-in-dotnet-csharp/llms.txt)
- [TX Text Control vs IronPDF for Enterprise PDF Workflows: Complete Comparison Guide](https://www.textcontrol.com/blog/2026/04/28/tx-text-control-vs-ironpdf-for-enterprise-pdf-workflows-complete-comparison-guide/llms.txt)
- [Using QR Codes in PDF Documents in C# .NET](https://www.textcontrol.com/blog/2026/04/21/using-qr-codes-in-pdf-documents-in-csharp-dotnet/llms.txt)
- [Programmatically Fill, Flatten, and Export DOCX Form Templates to PDF in C# .NET](https://www.textcontrol.com/blog/2026/04/10/programmatically-fill-flatten-and-export-docx-form-templates-to-pdf-in-csharp-dotnet/llms.txt)
- [Why Structured E-Invoices Still Need Tamper Protection using C# and .NET](https://www.textcontrol.com/blog/2026/03/24/why-structured-e-invoices-still-need-tamper-protection-using-csharp-and-dotnet/llms.txt)
- [Create Fillable PDFs from HTML Forms in C# ASP.NET Core Using a WYSIWYG Template](https://www.textcontrol.com/blog/2026/03/17/create-fillable-pdfs-from-html-forms-in-csharp-aspnet-core-using-a-wysiwyg-template/llms.txt)
- [Why HTML to PDF Conversion is Often the Wrong Choice for Business Documents in C# .NET](https://www.textcontrol.com/blog/2026/03/13/why-html-to-pdf-conversion-is-often-the-wrong-choice-for-business-documents-in-csharp-dot-net/llms.txt)
- [A Complete Guide to Converting Markdown to PDF in .NET C#](https://www.textcontrol.com/blog/2026/01/07/a-complete-guide-to-converting-markdown-to-pdf-in-dotnet-csharp/llms.txt)
- [Why PDF Creation Belongs at the End of the Business Process](https://www.textcontrol.com/blog/2026/01/02/why-pdf-creation-belongs-at-the-end-of-the-business-process/llms.txt)
