How to Create PDF Documents with TX Text Control using C# .NET on Linux
This article shows how to create professional PDF and PDF/A documents using ASP.NET Core C# on Linux. TX Text Control enables the creation of pixel-perfect PDF documents on any Linux environment that supports .NET, including Debian, Ubuntu, and Azure App Services.

Programmatic PDF generation is a common requirement in modern applications, whether for invoices, reports, or dynamically generated documents. While .NET developers have several options for PDF creation, achieving high-quality, feature-rich documents on Linux can be challenging.
In this tutorial, we'll explore how to use TX Text Control to create, modify, and export PDF documents in a C#.NET application running on Linux. We'll walk through the setup, cover the key APIs, and demonstrate how to create PDFs with text formatting, images, and tables - all while leveraging the power of TX Text Control's document processing capabilities.
You will have a fully functional .NET-based PDF creation solution running seamlessly on Linux by the end of this guide.
Prerequisites
You need to download and install the trial version of TX Text Control .NET Server:
- Download Trial Version
Setup download and installation required.
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; using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) { tx.Create(); // Add a paragraph to the document TXTextControl.Selection selection = new TXTextControl.Selection(0, 0); selection.Text = "Hello, Linux!"; // Set the paragraph format selection.ParagraphFormat = new ParagraphFormat() { Alignment = HorizontalAlignment.Center, BackColor = System.Drawing.Color.LightGray, Frame = Frame.BottomLine, FrameLineColor = System.Drawing.Color.Red, FrameStyle = FrameStyle.Double, FrameLineWidth = 10, }; // Set the font format selection.FontSize = 240; // 240 twips = 12 pt selection.FontName = "Arial"; selection.Bold = true; // Apply the changes to the document tx.Selection = selection; // Save the document tx.Save("results.pdf", TXTextControl.StreamType.AdobePDF); }
-
Now run the project that runs the application in a Docker container that uses the default Debian container with the .NET 8.0 runtime preinstalled.
It creates a new document, inserts a paragraph with a defined format-including borders, alignment, and character style-and then saves the document as a PDF file.
Adding Tables
Inserting tables into a document is as easy as adding text. The following code snippet demonstrates how to create a table and apply formatting, including cell borders and background colors.
…
When viewed in Adobe Acrobat Reader, the PDF document looks like this:
Adding Headers and Footers
You can add headers and footers to a document using the Headers
using TXTextControl;
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
// Add a header
tx.Sections.GetItem().HeadersAndFooters.Add(HeaderFooterType.Header);
// Get the header/footer object
HeaderFooter headerFooter = tx.Sections.GetItem().HeadersAndFooters.GetItem(HeaderFooterType.Header);
// Add an image to the header
Image image = new Image("tx_logo.svg", 0);
headerFooter.Images.Add(image, HorizontalAlignment.Right, 1, ImageInsertionMode.AboveTheText);
// Add a text to the header
headerFooter.Selection.Text = "Header Text\r\n\r\n";
// Add a page number field to the header
headerFooter.Selection.Text = "Page ";
headerFooter.PageNumberFields.Add(new PageNumberField());
headerFooter.Selection.Text = " of ";
headerFooter.PageNumberFields.Add(new PageNumberField() { ShowNumberOfPages = true });
// Add a new page
tx.Selection.Text = "\f";
// Save the document
tx.Save("results.pdf", StreamType.AdobePDF);
}
Here is the result when viewed in Adobe Acrobat Reader:
More PDF Options
TX Text Control provides advanced PDF settings, including encryption, compression, and PDF/A compliance. Developers can configure digital signatures and PDF/A compliance using the SaveSettings class. When opened in Acrobat Reader, the document displays a compliance notification and allows signature verification.
In addition, TX Text Control supports PDF/A-3 compliant documents, enabling embedded files. Developers can set UserPassword (to open the document) and MasterPassword (to manage access rights) to control permissions such as printing and form field creation.
Conclusion
TX Text Control provides a powerful document processing API for .NET developers to create, modify, and export PDF documents in Linux environments. By following this guide, you will have learned how to create a .NET application that generates high-quality PDFs with text formatting, images, tables, headers, footers, and advanced PDF settings.
TX Text Control enables the creation of pixel-perfect PDF documents on any Linux environment that supports .NET, including Debian, Ubuntu, and Azure App Services.
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
Convert MS Word DOCX to PDF including Text Reflow using .NET C# on Linux
This article explains how to use TX Text Control .NET Server to convert a Microsoft Word DOCX document to a PDF file on a Linux system using .NET C#. This conversion process includes text reflow,…
TX Text Control Linux Preview: Font Handling
TX Text Control for Linux introduces a revamped, cross-platform font rendering system that eliminates the need for manual font installation. The new Linux version simplifies deployment by offering…
Mining PDFs with Regex in C#: Practical Patterns, Tips, and Ideas
Mining PDFs with Regex in C# can be a powerful technique for extracting information from documents. This article explores practical patterns, tips, and ideas for effectively using regular…
Streamline Data Collection with Embedded Forms in C# .NET
Discover how to enhance your C# .NET applications by embedding forms for data collection. This article explores the benefits of using Text Control's ASP.NET and ASP.NET Core components to create…
Adding QR Codes to PDF Documents in C# .NET
This article explains how to add QR codes to PDF documents with the Text Control .NET Server component in C#. It provides the necessary steps and code snippets for effectively implementing this…