# Designing the Perfect Contract Template for MailMerge in C#

> This article shows how to create a contract template for MailMerge in C# using the TX Text Control .NET Server component. It uses JSON data to merge the template with the data including table of contents and conditional blocks.

- **Author:** Bjoern Meyer
- **Published:** 2024-09-26
- **Modified:** 2026-07-17
- **Description:** This article shows how to create a contract template for MailMerge in C# using the TX Text Control .NET Server component. It uses JSON data to merge the template with the data including table of contents and conditional blocks.
- **5 min read** (936 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - Contract
  - MailMerge
  - Template
- **Web URL:** https://www.textcontrol.com/blog/2024/09/26/designing-the-perfect-contract-template-for-mailmerge-in-csharp/
- **LLMs URL:** https://www.textcontrol.com/blog/2024/09/26/designing-the-perfect-contract-template-for-mailmerge-in-csharp/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2024/09/26/designing-the-perfect-contract-template-for-mailmerge-in-csharp/llms-full.txt

---

One of TX Text Control's strengths is the ability to generate dynamic contracts and agreements of all types. With pixel-perfect rendering, 100% content control, and text floating, paragraphs and dynamic sections can be perfectly aligned. Other reporting approaches, such as band reporting, do not offer such granularity.

In this article, we will guide you through various features of the design aspects for the pixel-perfect, dynamic contract generated from JSON data.

The template will provide the following features:

- Section-based headers and footers
- Table of contents
- Dynamic, conditional sections
- Signature blocks
- Dynamic footnotes

![Contract Template in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/contract.webp "Contract Template in TX Text Control")

### JSON Data Source

TX Text Control's reporting engine merges data from various data sources into a template. The data source can be a database, a JSON object, or any other data source. In this example, we are using a JSON object to merge data into the template.

The following JSON object represents a contract with placeholders for the dynamic data:

```
[
    {
        "contract_date": "2020-01-01",
        "provider": {
            "name": "Service Provider LLC",
            "address": "123 Main St, IL 62701 Springfield",
            "contact": {
                "name": "John Doe",
                "title": "CEO"
            }
        },
        "client": {
            "name": "Client LLC",
            "address": "456 Elm St, IL 62701 Springfield",
            "contact": {
                "name": "Jane Doe",
                "title": "CFO"
            }
        },
        "service": [
            {
                "type": "Service 1",
                "detail": "Service 1 details",
                "start_date": "2020-01-01",
                "end_date": "2020-12-31",
                "payment": {
                    "amount": 1000,
                    "terms": "net 30",
                    "frequency": "monthly",
                    "due_days": "30 days",
                    "late_fee": 50
                }
            }
        ],
        "expense_days": "30 days",
        "termination": {
            "notice_days": 30,
            "cause_days": 30
        },
        "law": "Illinois",
        "arbitration_body": "AAA",
        "section_intellectual_property": {
            "ownership": "Client",
            "license": "exclusive"
        },
        "section_indemnification" : {}
    }
]
```

### Template Design

The template contains merge fields that are replaced with data from the JSON object. The following screenshot shows the first page of the contract template with merge fields:

![Contract Template in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/page1.webp "Contract Template in TX Text Control")

This template page uses several different features, including section-based headers and footers, a table of contents, and merge fields that access data from different hierarchy levels. For example, the provider name is accessed from the JSON structure by the property *name* of the *provider* object using the dot notation *provider.name*.

The following screenshot shows the second page of the contract template with some other interesting features:

![Contract Template in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/page2.webp "Contract Template in TX Text Control")

### Conditional Blocks

The sections highlighted in red are conditional merge blocks. In the JSON data, you will find an entry for *section\_intellectual\_property*, which is also the block name of the first highlighted block.

```
"section_intellectual_property": {
    "ownership": "Client",
    "license": "exclusive"
},
```

The properties for the *ownership* and *license* fields come from this object. But the interesting part is the data itself. If you remove the *section\_intellectual\_property* element from the JSON data during the merge process, the entire section is not rendered.

The same is true for the *section\_indemnification* merge block, which also contains a footnote (red circle). The following results are returned when these elements are missing from the passed JSON data.

![Contract Template in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/page2_no_section.webp "Contract Template in TX Text Control")

As a result, you can see that the entire *Intelligent Property* and *Indemnification* sections have been removed. And with that, the included footnotes are removed as well. With floating text, all numbered list items are re-counted and the text flows properly to fit the page.

In the following animated screenshot, you can see both merge processes, one with the conditional blocks and one without the conditional blocks.

![Contract Template in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/animation_template.gif "Contract Template in TX Text Control")

### Signature Blocks

The last page contains the signature blocks with signature fields for capturing electronic signatures in the PDF or when using the Document Viewer.

![Contract Template in TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/page4.webp "Contract Template in TX Text Control")

When signed, these signature fields can be digitally signed using a certificate to create an encrypted and secure Adobe PDF document.

### Using MailMerge

TX Text Control's MailMerge class is used to merge the JSON data into the template. The following code snippet shows how to merge the JSON data into the template and save the resulting document as a PDF file:

```
using TXTextControl.DocumentServer;

using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
    tx.Create();
    tx.Load("acme_agreement.tx", TXTextControl.StreamType.InternalUnicodeFormat);

    MailMerge mailMerge= new MailMerge() { TextComponent = tx };
    string json = System.IO.File.ReadAllText("data.json");
    
    mailMerge.MergeJsonData(json, true);

    foreach (TXTextControl.TableOfContents toc in tx.TablesOfContents)
    {
        toc.Update();
    }

    tx.Save("results.pdf", TXTextControl.StreamType.AdobePDF);
}
```

### Download

> **Download**
> 
> You can download the template and the sample JSON data from the link below and use it for your own testing purposes.
> 
> [acme\_agreement.zip ](https://s1-www.textcontrol.com/assets/dist/blog/2024/09/26/a/assets/acme_agreement.zip)

### Conclusion

TX Text Control's reporting engine is a powerful tool for creating dynamic contracts and agreements. With the ability to merge data from multiple data sources into one template, you can create pixel-perfect documents with dynamic content. Conditional blocks, floating text, and dynamic footnotes are just a few of the features that make TX Text Control the perfect tool for creating contracts and agreements.

The template design is flexible and can be customized to meet your specific needs. Signature blocks can be used to capture electronic signatures and create secure PDF documents.

---

## 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

- [Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET](https://www.textcontrol.com/blog/2025/04/08/generating-dynamic-ndas-using-tx-text-control-mailmerge-in-csharp-dotnet/llms.txt)
- [Building a Production-Ready PDF Generation Pipeline in C# with ASP.NET Core](https://www.textcontrol.com/blog/2026/10/12/reliable-pdf-generation-pipeline-csharp-aspnet-core/llms.txt)
- [Create SignFabric Envelopes from Mail Merge Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/23/create-signfabric-envelopes-from-mail-merge-templates-using-dotnet-csharp/llms.txt)
- [Use MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX Templates](https://www.textcontrol.com/blog/2025/05/27/use-mailmerge-in-dotnet-on-linux-to-generate-pixel-perfect-pdfs-from-docx-templates/llms.txt)
- [Designing a Maintainable PDF Generation Web API in ASP.NET Core (Linux) C# with Clean Architecture and TX Text Control](https://www.textcontrol.com/blog/2025/03/27/designing-a-maintainable-pdf-generation-web-api-in-asp-net-core-linux-c-sharp-with-clean-architecture-and-tx-text-control/llms.txt)
- [Manipulating Table Cells During the MailMerge Process in .NET C#](https://www.textcontrol.com/blog/2024/12/03/manipulating-table-cells-during-the-mailmerge-process-in-net-csharp/llms.txt)
- [When to Generate Documents Server-Side Instead of Client-Side: A Focus on Data Security](https://www.textcontrol.com/blog/2024/10/04/when-to-generate-documents-server-side-instead-of-client-side-a-focus-on-data-security/llms.txt)
- [Mail Merge: Inserting Merge Blocks using the DataSourceManager in C#](https://www.textcontrol.com/blog/2024/10/02/mail-merge-inserting-merge-blocks-using-the-datasourcemanager-in-csharp/llms.txt)
- [Creating Advanced Tables in PDF and DOCX Documents with C#](https://www.textcontrol.com/blog/2024/09/30/creating-advanced-tables-in-pdf-and-docx-documents-with-csharp/llms.txt)
- [Video Tutorial: Creating a MailMerge Template and JSON Data Structure](https://www.textcontrol.com/blog/2024/08/16/video-tutorial-creating-a-mailmerge-template-and-json-data-structure/llms.txt)
- [Getting Started Video Tutorial: How to use the MailMerge and ServerTextControl Classes in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-use-the-mailmerge-and-servertextcontrol-classes-in-asp-net-core-c/llms.txt)
- [Getting Started Videos: New Text Control YouTube Channel](https://www.textcontrol.com/blog/2024/08/02/getting-started-videos-new-text-control-youtube-channel/llms.txt)
- [Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C# Applications](https://www.textcontrol.com/blog/2024/07/30/best-practices-for-mail-merge-and-form-field-processing-in-asp-net-core-csharp-applications/llms.txt)
- [Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF Template Engines in .NET C#](https://www.textcontrol.com/blog/2024/07/29/advantages-of-flow-type-layout-reporting-vs-banded-reporting-or-pdf-template-engines-in-net-c-sharp/llms.txt)
- [Designing a MailMerge Web API Endpoint with ASP.NET Core in C#](https://www.textcontrol.com/blog/2024/07/12/designing-a-mailmerge-web-api-endpoint-with-asp-net-core-in-c-sharp/llms.txt)
- [Enhancing Documents with QR Codes and Barcodes in .NET C#: A Comprehensive Guide](https://www.textcontrol.com/blog/2024/07/11/enhancing-documents-with-qr-codes-and-barcodes-in-net-csharp-a-comprehensive-guide/llms.txt)
- [Document Automation 101: Leveraging TX Text Control for Business Efficiency in .NET C# Applications](https://www.textcontrol.com/blog/2024/07/09/document-automation-101-leveraging-tx-text-control-for-business-efficiency-in-net-c-applications/llms.txt)
- [Merging Templates with MailMerge with Different Merge Field Settings in C#](https://www.textcontrol.com/blog/2023/12/16/merging-templates-with-mailmerge-with-different-merge-field-settings/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Use Case: Blood Pressure Report with Charts in C#](https://www.textcontrol.com/blog/2023/04/27/use-case-blood-pressure-report-with-charts-in-csharp/llms.txt)
- [MailMerge: Working with Image Placeholders](https://www.textcontrol.com/blog/2022/12/22/mailmerge-working-with-image-placeholders/llms.txt)
- [Getting Started: ServerTextControl and MailMerge with ASP.NET Core](https://www.textcontrol.com/blog/2022/09/01/getting-started-servertextcontrol-and-mailmerge-with-aspnet-core/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
