Different Ways to Create Documents using Text Control Products
There are many ways to create documents using Text Control products. This article gives an overview of different approaches using our products.

Text Control products can be used to create documents programmatically from scratch, pre-designed templates can be used to populate merge fields using the TXText
Creating Documents From Scratch
TX Text Control provides a powerful and complete API to create and manipulate documents programmatically. This API can be used in any .NET application such as Windows applications, Windows Service applications or web services.
The following code creates a new instance of a TXText
The code inserts a paragraph, a table and exports the document as an Adobe PDF document:
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
// create a new selection range
Selection range = new Selection();
range.Bold = true;
range.FontSize = 400;
range.Text = "This is a new paragraph\r\n";
// insert the range to the document
tx.Selection = range;
// add a table
tx.Tables.Add(5, 5, 10);
foreach (TableCell cell in tx.Tables.GetItem(10).Cells)
{
cell.Text = cell.Row.ToString() + ", " + cell.Column.ToString();
}
// save the document as PDF
tx.Save("test.pdf", StreamType.AdobePDF);
}
Merging Templates Using MailMerge
After a template has been successfully designed in one of the visual rich text controls of TX Text Control or in MS Word, the reporting engine TXText
A data source can be any IEnumerable object (business objects), JSON objects, DataSet and DataTable objects. Text Control Reporting follows the concept of pre-shaped data where data queries are executed before data is passed to the merge process.
The following code creates an instance of the reporting engine MailMerge to merge the template that is loaded into a ServerTextControl with an IEnumaerable object. Finally, the document is exported as a PDF document:
// create a business object that is used
// as the data source
Invoice invoice = new Invoice() { Name = "Report" };
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
LoadSettings ls = new LoadSettings() {
ApplicationFieldFormat = ApplicationFieldFormat.MSWord
};
// load the created template
tx.Load("template.docx", StreamType.WordprocessingML, ls);
// create a new MailMerge engine
using (MailMerge mailMerge = new MailMerge())
{
// connect to ServerTextControl
mailMerge.TextComponent = tx;
// merge the template that is loaded with
// the business object
mailMerge.MergeObject(invoice);
}
// export the document as PDF
tx.Save("test.pdf", StreamType.AdobePDF);
}
Editing Documents Using MS Word-Compatible Editors
The TXText
Not being dependent on an additional third-party tool such as MS Word to create templates is a very important key aspect when implementing word processing functionality into business applications. The MS Word compatible editor has the look and feel of MS Word, but can be customized and adapted to user requirements. MS Word templates can be reused and edited in TX Text Control.
Templates can be stored in industry standard(ized) formats such as DOCX, DOC and RTF and are always compatible with other word processors such as MS Word.
The following screenshot shows the Windows Forms version of TX Text Control. The visual controls can be automated in the same way like the non-visual class ServerTextControl using the same, compatible API.
Creating Documents in the Cloud
The ReportingCloud Web API can be used to merge MS Word compatible templates with JSON data from all clients such as .NET, .NET Core, Javascript, PHP, Node.JS, jQuery, Python, Android, Java, iOS and many more.
ReportingCloud provides a RESTful Web API to manage templates and to merge templates with hierarchical data from JSON strings.
The following code uses ReportingCloud and the ReportingCloud .NET Wrapper to merge data into a template:
ReportingCloud rc = new ReportingCloud(
"username",
"password",
new Uri("https://api.reporting.cloud"));
// create dummy data
Invoice invoice = new Invoice();
// create a new MergeBody object
MergeBody body = new MergeBody();
body.MergeData = invoice;
// merge the document
List<byte[]> results = rc.MergeDocument(body, templateName, ReturnFormat.PDF);
Conclusion
Text Control provides the most powerful tools and controls to integrate document creation processes into any kind of business applications.
Also See
This post references the following in the documentation:
TX Text Control .NET for Windows Forms
- TXText
Control. Document Server. Mail Merge Class - TXText
Control. Server Text Control Class - TXText
Control. Text Control Class
TX Text Control .NET for WPF
- TXText
Control. WPF. Ribbon Reporting Tab Class - TXText
Control. WPF. Text Control Class
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
MailMerge: Conditional Table Cell Colors using Filter Instructions
The MailMerge class provides an extensible framework to inject custom logic to the merge process. This sample shows how to implement conditional table cell colors.
MailMerge: Using Filters to Remove Unwanted Rows
Data in merge blocks can be filtered and sorted. This article explains how to use filters to remove unwanted lines.
Creating Templates: Typical Invoice Elements
This article shows the structure of a typical invoice template that can be used with TX Text Control and ReportingCloud.
TX Text Control 32.0 Has Been Released
We are pleased to announce the immediate availability of TX Text Control 32.0 for all platforms including ASP.NET, Windows Forms, WPF and ActiveX.
An Ultimate Guide to Mail Merge with MS Word Documents in C#
The MailMerge class provides very effective ways to merge data into MS Word compatible templates. This updated ultimate guide provides an overview of all the important features and functionalities…