Products Technologies Demo Docs Blog Support Company

Converting MS Word DOCX Documents to PDF in C#

Use TX Text Control to programmatically convert MS Word DOC and DOCX documents to PDF. This article outlines the requirements and explains the simple steps you need to take to successfully convert Office documents to Adobe PDF.

Converting MS Word DOCX Documents to PDF in C#

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 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.

  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!");
    }

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#

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

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.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETArchivingDOCX

From DOCX to Long-Term Archiving: Generating PDF/A from Office Documents in…

This article explores how to convert DOCX files to the PDF/A format using the .NET C# programming language. We discuss why PDF/A is important for long-term archiving and provide a step-by-step…


ASP.NETConversionDOCX

PDF Conversion in .NET: Convert DOCX, HTML and more with C#

PDF conversion in .NET is a standard requirement for generating invoices, templates, and accessible reports. This article provides an overview of PDF conversion capabilities using TX Text Control,…


ASP.NETASP.NET CoreDOCX

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,…


ASP.NETASP.NET CoreDOCX

Use MailMerge in .NET on Linux to Generate Pixel-Perfect PDFs from DOCX…

This article explores how to use the TX Text Control MailMerge feature in .NET applications on Linux to generate pixel-perfect PDFs from DOCX templates. This powerful combination enables…


ASP.NETASP.NET CoreDOCX

How to Import and Read Form Fields from DOCX Documents in .NET on Linux

Learn how to import and read form fields from DOCX documents in .NET on Linux using TX Text Control. This article provides a step-by-step guide to help you get started with form fields in TX Text…