Getting Started: ServerTextControl and MailMerge in a .NET 8 Console Application on Linux with Docker and WSL
This article shows how to create a .NET 8 console application on Linux using Docker and WSL that uses the ServerTextControl to create a document and MailMerge to merge JSON data into the document. The document is saved as a PDF file.

Prerequisites
You need to download and install the trial version of TX Text Control .NET Server.
- Download Trial Version
Setup download and installation required.
Introduction
This tutorial shows how to use Visual Studio 2022 to create an .NET 8 console application that uses the ServerTextControl and MailMerge classes from TX Text Control .NET Server. The application is hosted in a Docker container using a Linux base image.
Creating the Application
Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the .NET 8 SDK.
-
In Visual Studio 2022, create a new project by choosing Create a new project.
-
Select Console App as the project template and confirm with Next.
-
Enter a project name and choose a location to save the project. Confirm with Next.
-
Choose .NET 8.0 (Long Term Support) as the Framework.
-
Enable the Enable container support checkbox and choose Linux as the Container OS.
-
Choose Dockerfile for the Container build type option and confirm with Create.

Adding the NuGet Packages
-
In the Solution Explorer, select your created project and choose Manage NuGet Packages... from the Project main menu. Select Text Control Offline Packages as the Package source.
Install the following package:
- TXTextControl.TextControl.Core.SDK

Using ServerTextControl and MailMerge
-
Find the Program.cs file in the Solution Explorer and replace the code with the following code snippet:
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) { // Create a new ServerTextControl instance tx.Create(); // Adding static text with formatting TXTextControl.Selection sel = new TXTextControl.Selection { Text = "Welcome to Text Control\r\n", // Static welcome message Bold = true // Apply bold formatting }; tx.Selection = sel; // Adding a merge field for dynamic data insertion TXTextControl.DocumentServer.Fields.MergeField mergeField = new TXTextControl.DocumentServer.Fields.MergeField { Text = "{{company}}", // Placeholder text in the document Name = "company", // Internal name for the merge field TextBefore = "Company name: " // Prefix text before the field }; // Add the merge field to the document tx.ApplicationFields.Add(mergeField.ApplicationField); // ---- Optionally load a template ---- // If a predefined document template is available, uncomment the following lines /* TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings { ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord // Preserve Word field format }; tx.Load("template.docx", TXTextControl.StreamType.WordprocessingML, ls); */ // Perform mail merge using JSON data using (TXTextControl.DocumentServer.MailMerge mailMerge = new TXTextControl.DocumentServer.MailMerge()) { mailMerge.TextComponent = tx; // Link MailMerge engine to the text component // JSON data to be merged into the document string jsonData = "[{\"company\": \"Text Control, LLC\" }]"; mailMerge.MergeJsonData(jsonData); // Merge the provided JSON data } tx.Save("results.pdf", TXTextControl.StreamType.AdobePDF); Console.WriteLine("Document created: results.pdf"); }
Run with Docker
-
Select Container (Dockerfile) as the startup profile and start the application.

Run with WSL
For a faster development experience, you can run the application in WSL (Windows Subsystem for Linux).
-
Select WSL as the startup profile and start the application.

Enable WSL (Windows Subsystem for Linux)
In case you haven't enabled WSL yet, follow these steps:
Enable WSL (Windows Subsystem for Linux)
Open PowerShell as an administrator.
Run the following command:
wsl --installThis installs the default Linux distribution (usually Ubuntu) and enables necessary features.
- After the installation, restart your computer.
Set WSL 2 as the Default Version
To set WSL 2 as the default version, follow these steps:
Open PowerShell as an administrator.
Run the following command:
wsl --set-default-version 2If you haven't installed a Linux distribution yet, you can do so via:
wsl --install -d Ubuntu
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.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
Announcing the Official DS Server Docker Image on Docker Hub
The official DS Server Docker image is now available on Docker Hub. This makes it easier to deploy the DS server in a containerized environment and manage and scale your applications. Based on the…
Using TX Text Control with Ultra-Minimal Chiseled Linux Containers
This article shows how to create ultra-lightweight, chiseled Linux containers for ASP.NET Core applications using TX Text Control .NET Server 33.0.
Getting Started: Document Editor with ASP.NET Core and Docker Support with…
This article shows how to create a simple ASP.NET Core application using the Document Editor and deploy it in a Docker container on Linux. The article shows how to use the NuGet packages and how…
ASP.NET Core: Deploying the TX Text Control 32.0 SP2 Document Editor to Linux
To deploy the TX Text Control 32.0 SP2 Document Editor on Linux as part of an ASP.NET Core Web application, the synchronization service must be deployed separately on a Windows VM. This allows the…
ASP.NET Core: Deploying the TX Text Control Document Editor to Linux
In order to deploy the TX Text Control document editor to Linux as part of an ASP.NET Core (.NET 5) Web Application, the synchronization service must be deployed separately to a Windows VM. This…
