Products Technologies Demo Docs Blog Support Company

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.

Designing the Perfect Contract Template for MailMerge in C#

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

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

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

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

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

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

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

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.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETASP.NET CoreContract

Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET

This article demonstrates how to generate dynamic NDAs using TX Text Control MailMerge in C# .NET. It covers the process of creating a template, binding data, and generating the final document.


ASP.NETASP.NET CoreDOCX

Use MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX…

This article explores how to use the TX Text Control MailMerge feature in .NET applications on Linux to generate pixel-perfect PDFs from DOCX templates. This powerful combination enables…


ASP.NETASP.NET CoreBackend

Designing a Maintainable PDF Generation Web API in ASP.NET Core (Linux) C#…

This article shows how to create a PDF generation Web API in ASP.NET Core on Linux using TX Text Control .NET Server. The clean architecture is used to create a maintainable and testable solution.


ASP.NETASP.NET CoreMailMerge

Manipulating Table Cells During the MailMerge Process in .NET C#

This article shows how to manipulate table cells during the mail merge process in .NET C#. The FieldMerged event can be used to manipulate the table cells after they are merged.


ASP.NETASP.NET CoreMailMerge

When to Generate Documents Server-Side Instead of Client-Side: A Focus on…

When it comes to document generation, deciding whether to handle the task server-side or client-side is a key architectural decision for any organization. This article discusses the benefits of…