TX Text Control .NET Server

Mail Merge Examples

Topic

A merge has two halves, and the examples cover both: designing a template with merge fields and blocks, usually in the Document Editor, and merging it with data on the server with MailMerge. The online demos show each reporting structure with its template, data and code, from a single merge block to conditional sections. The sample projects put the merge into applications: Web APIs, background queues, Blazor and dynamic contracts.

Online Demos: Merging on the Server

These demos merge data into a template with MailMerge on the server:

ExampleWhat it showsWhere
ConceptBusiness data that a user enters merged into a template on the serverMail Merge Concept
Merge blocksRepeating regions of a template filled from nested JSON arraysMerge Blocks
Alternating rowsTable rows in two alternating colorsAlternating Row Colors
Conditional sectionsRegions of the template removed when their data is emptyConditional Sections
Conditional fieldsText chosen by IF fields from the values of the dataConditional Fields
BarcodesBarcodes filled with values from the dataMerging Barcodes
ImagesNamed image placeholders replaced by base64-encoded images from the dataMerging Images
Number formatsNumeric formats defined in the template applied to raw valuesString Formatter
PrefixesValues of related objects addressed with table name prefixes and dot notationUsing Prefixes
Merging in codeA template built from fields in code and merged with JSON data, in the interactive labMail Merge with JSON

Online Demos: Designing Templates

These demos design templates in the Document Editor:

ExampleWhat it showsWhere
OverviewA template designed and merged with data in the editorMail Merge Overview
Template AssistantFields and merge blocks inserted from the data, with sorting, filters and conditionsMail Merge Template Assistant
Nested blocksTables with nested repeating merge blocks designed from JSON dataNested Merge Block Designer
Data source from JavaScriptJSON data passed to the editor in the browser with loadJsonData, so that users insert fields and repeating blocks from it on the Reporting tabData Source from JavaScript
Conditional blocksMerge blocks merged only when a condition on the parent data is metConditional Merge Blocks
Sub-templatesTemplates included in a main template with IncludeText fieldsMerging Sub-Templates
FormulasTable formulas that calculate merged valuesMail Merge and Formulas
ContractsContracts with dynamic sections generated from a templateDynamic Contract Generation
Merging from the editorThe template of the editor merged on the server and exported as PDFMerge using MailMerge

The blog article Learning Mail Merge Templates from Basic Fields to Advanced Reporting Structures leads through these demos from simple fields to complex reports.

Sample Projects

ExampleWhat it showsWhere
Dynamic NDAsSections of an NDA template included or left out depending on the JSON data, as described in Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET. Version 33.0TXTextControl.Server.NDA.Dynamic
Templates and formsA template designed in the Document Editor, merged with data and filled out as a form in the Document Viewer in one ASP.NET Core application, as described in Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C# Applications. Version 33.0TXTextControl.Server.Core.BestPractice
BlazorA template in the Blazor Document Editor merged with data and saved as PDF, as described in TX Text Control for Blazor: Mail Merge Integration Tutorial. Version 33.0TXTextControl.Web.Blazor.MailMerge
Web API endpointAn endpoint that receives a template, data and merge settings and returns a PDF, as described in Designing a MailMerge Web API Endpoint with ASP.NET Core in C#. Version 33.0 with the Classic engineTXTextControl.MailMerge.WebAPI
Templates in a databaseTemplates created in the editor, stored in LiteDB and merged from there, as described in Store and Merge Templates in a Database using LiteDB and ASP.NET Core C#. Version 33.0 with the Classic engineTextControl.DocumentStorage
Mustache placeholdersA class that turns {{mustache}} placeholders, including blocks, into merge fields and merge blocks before the merge, as described in Mail Merge: Merging Templates with Mustache Syntax in C#. The repository contains the class onlyMustacheMatcher
Barcodes and QR codesA packing slip merged from JSON data whose barcodes and QR codes take their values from the data, as described in Enhancing Documents with QR Codes and Barcodes in .NET C#: A Comprehensive Guide. Version 33.0 with the Classic engineTXTextControl.Server.Barcodes
AngularTemplates designed in the Angular Document Editor and merged with JSON data by an ASP.NET Core Web API, as described in MailMerge with Angular and ASP.NET Core. Version 32.0TXTextControl.Server.Angular.MailMerge
Background queueA Web API that queues document requests, creates the documents in a hosted service and notifies the client through a webhook, as described in Queuing and Generating Documents using an IHostedService and WebHooks. Version 31.0 on .NET 6TextControl.Web.MVC.MailMerge.BackgroundWorker

The PDF generation Web API for Linux is listed in Document Processing Examples, and the samples that create electronic invoices with a merge in PDF Examples.

Blog Articles With Code

ExampleWhat it showsWhere
Parallel mergingMany merge jobs processed at the same time in worker processes with TXTextControl.DocumentServer.ParallelMailMerge, with a benchmarkCreate 100,000 Documents in Under an Hour with Parallel MailMerge in .NET C#
Merging on LinuxDOCX templates merged into PDF documents in a .NET console application on LinuxUse MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX Templates
Sorting and filteringThe rows of merge blocks sorted and filteredFiltering and Sorting Repeating Blocks in MailMerge using C#
Business objects with totalsObjects that calculate their own sums merged into a templateMerging Self-Calculating Business Objects with TX Text Control MailMerge in C#
One document or manySeveral records merged into one document with first-page headers and footers, or into separate documentsMerging Multiple Records with First-Page Headers and Footers
Merge blocks in codeMerge blocks inserted into a template with the DataSourceManagerMail Merge: Inserting Merge Blocks using the DataSourceManager in C#

Next Steps