If you need to programmatically convert an MS Word document in RTF, DOC or DOCX formats to PDF, TX Text Control provides an easy-to-use library to accomplish this task. Using advanced document processing technology, you can use a highly reliable C# API to create PDFs from MS Word documents without using printer drivers.

The following tutorial shows how to create a simple .NET 6 C# Console App to convert MS Word documents to PDF that uses the ServerTextControl TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
The ServerTextControl class implements a component that provide high-level text processing features for server-based applications.
class.

Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the .NET 6 SDK.

Prerequisites

The following tutorial requires a trial version of TX Text Control .NET Server for ASP.NET.

  1. In Visual Studio 2022, create a new project by choosing Create a new project.

  2. Select Console App as the project template and confirm with Next.

  3. Choose a name for your project and confirm with Next.

  4. In the next dialog, choose .NET 6 (Long-term support) as the Framework and confirm with Create.

Adding the NuGet Package

  1. In the Solution Explorer, select your created project and choose Manage NuGet Packages... from the Project main menu.

    Select Text Control Offline Packages from the Package source drop-down.

    Install the latest versions of the following package:

    • TXTextControl.TextControl.ASP.SDK

    ASP.NET Core Web Application

Adding Documents

  1. In the Solution Explorer, select your created project and choose New Folder from the Project main menu and name it Documents.

  2. Select the newly created folder and choose Add Existing Item... from the Project main menu. Select any MS Word document from your local machine and click the Add button to confirm.

  3. Select the newly created file and set the Copy to Output Directory property to true.

Adding the Code

  1. Open the Program.cs file and replace the code with the following code:

    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
    {
    tx.Create();
    // load DOC or RTF file
    //tx.Load("mydocument.doc", TXTextControl.StreamType.MSWord);
    //tx.Load("mydocument.rtf", TXTextControl.StreamType.RichTextFormat);
    // load DOCX file
    tx.Load("Documents/mydocument.docx", TXTextControl.StreamType.WordprocessingML);
    // optionally set the save settings
    TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings()
    {
    Author = "Text Control",
    CreationDate = DateTime.Now,
    CreatorApplication = "TX Text Control Sample Application",
    DocumentAccessPermissions = TXTextControl.DocumentAccessPermissions.AllowAll
    };
    // save as PDF
    tx.Save("mydocument.pdf", TXTextControl.StreamType.AdobePDF, saveSettings);
    Console.WriteLine("Document has been converted!");
    }
    view raw test.cs hosted with ❤ by GitHub

Compile and start the application. The converted PDF document will be saved in the root folder of your project.

Different Ways to Generate PDFs

TX Text Control .NET allows developers to programmatically create PDF files using C# in a variety of ways, including creating documents from scratch, merging data into predefined templates, and converting documents such as HTML to PDF.

Learn More

TX Text Control allows developers to create PDF files programmatically using C#. This article shows various ways to create Adobe PDF documents.

Creating PDF Files using TX Text Control .NET in C#