# Merging Multiple Records with First-Page Headers and Footers

> This article demonstrates how to merge multiple records with first-page headers and footers using the MailMerge class of the TX Text Control .NET Server.

- **Author:** Bjoern Meyer
- **Published:** 2025-04-14
- **Modified:** 2025-11-16
- **Description:** This article demonstrates how to merge multiple records with first-page headers and footers using the MailMerge class of the TX Text Control .NET Server.
- **4 min read** (683 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - Headers and Footers
  - Sections
- **Web URL:** https://www.textcontrol.com/blog/2025/04/14/merging-multiple-records-with-first-page-headers-and-footers/
- **LLMs URL:** https://www.textcontrol.com/blog/2025/04/14/merging-multiple-records-with-first-page-headers-and-footers/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2025/04/14/merging-multiple-records-with-first-page-headers-and-footers/llms-full.txt

---

When merging multiple records using the TX Text Control's MergeJsonData method, the append parameter determines whether the output is a single document with each record in a new section or multiple separate documents.

Templates that contain only a first page header can be tricky in scenarios where the append parameter is set to true to append all records to a resulting document. If set to false, individual documents are created and the first page header is only visible on page 1.

### The Problem

But when appended, the first page header is rendered for all sections, and if the header contains merge fields, they are populated with data from the first record. So basically, after the merge, you have all the records merged into separate sections, but the header and footer contain the merge field data from the first record.

Let's take a look at the following template:

![Section headers](https://s1-www.textcontrol.com/assets/dist/blog/2025/04/14/a/assets/header1.webp "Section headers")

You can see a first page header with a merge field and the main body containing a merge block. This is the JSON data that will be used to merge the content into the template.

```
[
    {
        "invoice": "INV-001",
        "date": "2023-10-01",
        "items": [
            {
                "name": "Widget A",
                "description": "A longer description of Widget A.",
                "quantity": 2,
                "unit_price": 10.00
            },
            {
                "name": "Widget B",
                "description": "A longer description of Widget B.",
                "quantity": 1,
                "unit_price": 20.00
            }
        ]
    },
    {
        "invoice": "INV-002",
        "date": "2023-10-02",
        "items": [
            {
                "name": "Widget C",
                "description": "A longer description of Widget C.",
                "quantity": 5,
                "unit_price": 5.00
            },
            {
                "name": "Widget D",
                "description": "A longer description of Widget D.",
                "quantity": 3,
                "unit_price": 15.00
            }
        ]
    }
]
```

The following code shows how to merge the JSON data into the template using the *MergeJsonData* method.

```
using System.IO;
using TXTextControl;
using TXTextControl.DocumentServer;

// Create and initialize a ServerTextControl instance
using var tx = new ServerTextControl();

// Create a new, empty document
tx.Create();

// Load the template in the internal Unicode format
tx.Load("template.tx", StreamType.InternalUnicodeFormat);

// Set up the MailMerge engine and assign the TextComponent
var mailMerge = new MailMerge
{
    TextComponent = tx
};

// Read JSON data from a file
var jsonData = File.ReadAllText("data.json");

// Merge JSON data into the loaded template
// `append: true` means merge all records into one document, each in a new section
mailMerge.MergeJsonData(jsonData, append: true);

// Save the merged result as a PDF file
tx.Save("result.pdf", StreamType.AdobePDF);
```

After the merge, the resulting document looks like this:

![Merged document](https://s1-www.textcontrol.com/assets/dist/blog/2025/04/14/a/assets/header2.webp "Merged document")

### The Solution

As you can see, the header of the second attached document contains the merge data from the first record. This is not what we want. A new section is added for each record, and a unique first page header should be added for all pages in each section. But we know that a new section is added for all records, so we can use a header and footer setting to implement this requirement.

For the first page header, we use the ConnectedToPrevious property and set it to false for the first page header. This means that the first page header is not connected to the header of the previous section.

![Merged document](https://s1-www.textcontrol.com/assets/dist/blog/2025/04/14/a/assets/header3.webp "Merged document")

Now the first page header is not linked to the previous section, and the merge field is populated with the data from the current record. Below is the resulting document after the merge:

![Merged document](https://s1-www.textcontrol.com/assets/dist/blog/2025/04/14/a/assets/header4.webp "Merged document")

As you can see, the first page header is now populated with the data from the current record.

### Conclusion

In this article, we learned how to use the MergeJsonData method to merge multiple records into a single document with a first page header. We also learned how to set the ConnectedToPrevious property to false for the first page header to ensure that it is not connected to the previous section.

By using this approach, we can ensure that the first page header is populated with the data from the current record and not the first record.

---

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

- [Find ApplicationFields within Sections and Paragraphs in .NET C#](https://www.textcontrol.com/blog/2024/08/02/find-applicationfields-within-sections-and-paragraphs-in-net-c-sharp/llms.txt)
- [Techorama 2026: Welcome to The Document Forge](https://www.textcontrol.com/blog/2026/05/15/techorama-2026-welcome-to-the-document-forge/llms.txt)
- [Signed CycloneDX SBOMs for CRA Compliance Available for Text Control Products](https://www.textcontrol.com/blog/2026/05/08/signed-cyclonedx-sboms-for-cra-compliance-available-for-text-control-products/llms.txt)
- [Introducing SignFabric: An Open Source, Enterprise-Ready E-Sign Platform Built with TX Text Control](https://www.textcontrol.com/blog/2026/05/06/introducing-signfabric-an-open-source-enterprise-ready-esign-platform-built-with-tx-text-control/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)
- [Building a Modern Track Changes Review Workflow in ASP.NET Core C#](https://www.textcontrol.com/blog/2026/04/28/building-a-modern-track-changes-review-workflow-in-aspnet-core-csharp/llms.txt)
- [Document Classification Without AI: Deterministic, Explainable, and Built for Production in C# .NET](https://www.textcontrol.com/blog/2026/04/23/document-classification-without-ai-deterministic-explainable-built-for-production-in-csharp-dot-net/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)
- [Sanitizing Data in Document Pipelines: A Practical Approach with TX Text Control in C# .NET](https://www.textcontrol.com/blog/2026/04/20/sanitizing-data-in-document-pipelines-a-practical-approach-with-tx-text-control-in-csharp-dotnet/llms.txt)
- [One More Stop on Our Conference Circus: code.talks 2026](https://www.textcontrol.com/blog/2026/04/17/one-more-stop-on-our-conference-circus-code-talks-2026/llms.txt)
- [Build Your Own MCP-Powered Document Processing Backend with TX Text Control](https://www.textcontrol.com/blog/2026/04/16/build-your-own-mcp-powered-document-processing-backend-with-tx-text-control/llms.txt)
- [TXTextControl.Markdown.Core 34.1.0-beta: Work with Full Documents, Selection, and SubTextParts](https://www.textcontrol.com/blog/2026/04/14/txtextcontrol-markdown-core-34-1-0-beta-work-with-full-documents-selection-and-subtextparts/llms.txt)
- [5 Layout Patterns for Integrating the TX Text Control Document Editor in ASP.NET Core C#](https://www.textcontrol.com/blog/2026/04/09/5-layout-patterns-for-integrating-the-tx-text-control-document-editor-in-aspnet-core-csharp/llms.txt)
- [Extracting Structured Table Data from DOCX Word Documents in C# .NET with Domain-Aware Table Detection](https://www.textcontrol.com/blog/2026/04/03/extracting-structured-table-data-from-docx-word-documents-in-csharp-dotnet-with-domain-aware-table-detection/llms.txt)
- [Introducing Text Control Agent Skills](https://www.textcontrol.com/blog/2026/03/27/introducing-text-control-agent-skills/llms.txt)
- [Deploying the TX Text Control Document Editor from the Private NuGet Feed to Azure App Services (Linux and Windows)](https://www.textcontrol.com/blog/2026/03/25/deploying-the-tx-text-control-document-editor-from-the-private-nuget-feed-to-azure-app-services-linux-and-windows/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)
- [AI Generated PDFs, PDF/UA, and Compliance Risk: Why Accessible Document Generation Must Be Built Into the Pipeline in C# .NET](https://www.textcontrol.com/blog/2026/03/23/ai-generated-pdfs-pdf-ua-and-compliance-risk-why-accessible-document-generation-must-be-built-into-the-pipeline-in-c-sharp-dot-net/llms.txt)
- [File Based Document Repository with Version Control in .NET with TX Text Control](https://www.textcontrol.com/blog/2026/03/20/file-based-document-repository-with-version-control-in-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)
- [Inspect and Process Track Changes in DOCX Documents with TX Text Control with .NET C#](https://www.textcontrol.com/blog/2026/03/10/inspect-and-process-track-changes-in-docx-documents-with-tx-text-control-with-dotnet-csharp/llms.txt)
- [Text Control at BASTA! Spring 2026 in Frankfurt](https://www.textcontrol.com/blog/2026/03/06/text-control-at-basta-spring-2026-in-frankfurt/llms.txt)
- [From Legacy Microsoft Office Automation to a Future-Ready Document Pipeline with C# .NET](https://www.textcontrol.com/blog/2026/03/02/from-legacy-microsoft-office-automation-to-a-future-ready-document-pipeline-with-csharp-dot-net/llms.txt)
- [We are Gold Partner at Techorama Belgium 2026](https://www.textcontrol.com/blog/2026/02/26/we-are-gold-partner-techorama-belgium-2026/llms.txt)
