IRONSOFTWAREHOME

How to Convert Microsoft Word to PDF in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronPDF converts Word documents to PDF in C# through the DocxToPdfRenderer class: RenderDocxAsPdf takes a file path, a byte array, or a stream, and DocxPdfRenderOptions carries the Mail Merge and page setup settings. Every call returns a PdfDocument, so the same object then takes headers, a watermark, a password, or an archival export.

Word is where documents get written and PDF is where they get sent. The conversion sits at the end of most document pipelines: contracts going out for signature, invoices to customers, reports into an archive. A PDF holds its layout on any device, while a DOCX depends on the fonts and the Word version at the other end.

IronPDF has the ability to convert Word documents to PDF files instantly, along with providing a Mail Merge feature for generating personalized batches of documents for individual recipients. Converting from DOCX to PDF ensures universal compatibility, preserves formatting, and adds a layer of security. This functionality is particularly useful when you need to distribute documents that should maintain their exact appearance across different devices and operating systems, similar to creating PDFs from HTML or converting images to PDF.

Quickstart: Convert DOCX to PDF Using IronPDF

One class, one method, one line. DocxToPdfRenderer reads the file and RenderDocxAsPdf returns a PdfDocument ready to save.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    new IronPdf.DocxToPdfRenderer()
        .RenderDocxAsPdf("document.docx")
        .SaveAs("output.pdf");
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer
Tips: Working with an AI coding assistant? The AI setup guide shows how to point it at IronPDF's documentation, so the code it writes against this page compiles on the first try.

How Do I Convert a DOCX File to PDF?

IronPDF allows developers to convert Word documents to PDF programmatically, streamlining efficiency and allowing them to integrate into existing .NET applications or any cross-platform .NET framework applications they might have. The library supports various installation methods including NuGet packages and can be deployed across multiple platforms including Windows, Linux, and macOS.

Instantiate DocxToPdfRenderer, then call RenderDocxAsPdf with the path to your file. This method returns a PdfDocument object, allowing you to customize the PDF further, including adding headers and footers, applying watermarks, or setting security options. You can download the Modern Chronological Resume DOCX example file.

Input

Microsoft Word displaying a modern pharmacist resume with red accents in chronological format

How Do I Write the C# Code?

using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file
PdfDocument pdf = renderer.RenderDocxAsPdf("Modern-chronological-resume.docx");

// Save the PDF
pdf.SaveAs("pdfFromDocx.pdf");

Output

The resulting PDF preserves the original formatting, including fonts, colors, layout, and embedded images.


How Do I Convert DOCX from a Stream or Byte Array?

RenderDocxAsPdf also accepts a byte array or a stream, for documents that come from memory or a database rather than a file on disk:

// Convert from byte array
byte[] docxBytes = File.ReadAllBytes("document.docx");
PdfDocument pdfFromBytes = renderer.RenderDocxAsPdf(docxBytes);

// Convert from stream
using (FileStream stream = new FileStream("document.docx", FileMode.Open))
{
    PdfDocument pdfFromStream = renderer.RenderDocxAsPdf(stream);
}

Reading the same file as bytes or as a stream produces the identical PDF shown above; only how the document reaches the renderer changes.


How Do I Convert DOCX to PDF Asynchronously?

RenderDocxAsPdfAsync renders from a file path without blocking the calling thread, which matters in a web request or a desktop UI. The async overload only accepts a file path; the byte array and stream overloads above stay synchronous.

using IronPdf;

// Instantiate Renderer
DocxToPdfRenderer renderer = new DocxToPdfRenderer();

// Render from DOCX file without blocking the calling thread
PdfDocument pdf = await renderer.RenderDocxAsPdfAsync("document.docx");

// Save the PDF
pdf.SaveAs("pdfFromDocxAsync.pdf");
C#

The output is the same document rendered the same way; only the calling thread stays free while it runs.


How Can I Use Mail Merge for Batch PDF Generation?

Mail Merge, located on the "Mailings" tab in Microsoft Word, allows you to create a batch of documents with personalized information for each recipient or data entry. It's often used to generate personalized letters, envelopes, labels, or email messages, such as invitations, newsletters, or form letters, where much of the content is the same, but certain details vary for each recipient. This feature is particularly powerful when combined with IronPDF's ability to merge multiple PDFs or generate documents with custom metadata.

What Data Model Should I Create?

Create a model to hold the values that will be merged. The property names in your data model must match the merge field names in your Word template exactly (case-sensitive).

Please note: Property names must match the merge field names in the Word template exactly, including case. A mismatch renders the field empty rather than throwing.
internal class RecipientsDataModel
{
    public string Date { get; set; }
    public string Location{ get; set; }
    public string Recipients_Name { get; set; }
    public string Contact_Us { get; set; }
}

The template below is a Microsoft Word sample with merge fields added. Download the Party Invitation DOTX example file. Set the MailMergePrintAllInOnePdfDocument property to true to combine the PDFs into a single PdfDocument object. The merge fields used here are Date, Location, Recipient's Name, and Contact Us.

Input

Word mail merge party invitation template showing merge fields and Mailings ribbon with mail merge tools

How Do I Implement the Mail Merge Code?

The Mail Merge functionality in IronPDF supports various rendering options that can be configured through the DocxPdfRenderOptions class. This allows you to control aspects like page orientation, margins, and whether to combine all merged documents into a single PDF or generate separate files.

Tips: Set MailMergePrintAllInOnePdfDocument to true for one combined PDF, or leave it false to get a separate document per recipient.
using IronPdf;
using System.Collections.Generic;
using System.Linq;

var recipients = new List<RecipientsDataModel>()
    {
        new RecipientsDataModel()
        {
            Date ="Saturday, October 15th, 2023",
            Location="Iron Software Cafe, Chiang Mai",
            Recipients_Name="Olivia Smith",
            Contact_Us = "support@ironsoftware.com"
        },
        new RecipientsDataModel()
        {
            Date ="Saturday, October 15th, 2023",
            Location="Iron Software Cafe, Chiang Mai",
            Recipients_Name="Ethan Davis",
            Contact_Us = "support@ironsoftware.com"
        },
    };

DocxToPdfRenderer docxToPdfRenderer = new DocxToPdfRenderer();

// Apply render options
DocxPdfRenderOptions options = new DocxPdfRenderOptions();

// Configure the output PDF to be combined into a single PDF document
options.MailMergePrintAllInOnePdfDocument = true;

// Convert DOTX to PDF
var pdfs = docxToPdfRenderer.RenderDocxMailMergeAsPdf<RecipientsDataModel>(
     recipients,
     "Party-invitation.dotx",
     options);

pdfs.First().SaveAs("mailMerge.pdf");

Output

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.

David Jones

Lead Software Engineer, Agorus Build

View case study

Conclusion

DocxToPdfRenderer converts a Word file, a byte array, or a stream into a PdfDocument with one call, and DocxPdfRenderOptions turns that same call into a Mail Merge run across a whole recipient list. What you get back is an ordinary IronPDF document, so anything the library does to a PDF, it does to this one.

Please note: Converting a DOCX is usually step one. The same PdfDocument then takes PDF/A or PDF/UA export, a digital signature, or permissions and a password.

From here, export the result to disk, memory, or an HTTP response, or convert from a different source with Markdown to PDF and RTF to PDF.


Troubleshooting


Questions?

If you have any questions, reach out to support@ironsoftware.com

Frequently Asked Questions

What is the main functionality of DocxToPdfRenderer in IronPDF?

The DocxToPdfRenderer class in IronPDF is used to convert Microsoft Word documents (DOCX) into PDF format. This conversion ensures that the document's layout is maintained across devices, preserving its fonts, colors, and overall structure.

How can IronPDF assist with Mail Merge operations?

IronPDF supports Mail Merge through the DocxPdfRenderOptions class, enabling users to generate batches of personalized documents. This is especially useful for creating bulk communications, like personalized letters, where each document needs unique recipient data.

Can IronPDF handle DOCX input from sources other than files?

Yes, IronPDF's RenderDocxAsPdf method can also process DOCX content from a byte array or a stream, making it ideal for documents stored in memory or databases.

How does the asynchronous conversion of DOCX to PDF improve performance?

Using RenderDocxAsPdfAsync allows the DOCX to PDF conversion to happen without blocking the calling thread, which is beneficial in environments like web servers or desktop applications where maintaining responsiveness is critical.

What benefits does converting DOCX to PDF provide?

Converting DOCX to PDF ensures universal compatibility across devices and operating systems, maintains document formatting, and adds a layer of security, making PDFs ideal for sharing finalized documents.

How does IronPDF ensure document layout is preserved during conversion?

IronPDF preserves the original formatting of documents during conversion by accurately retaining fonts, colors, layout, and embedded images, resulting in a PDF that mirrors the original DOCX appearance.

Is it possible to render a Microsoft Word document to PDF in one line of code using IronPDF?

Yes, IronPDF allows DOCX to PDF conversion in one line of C# code by instantiating a DocxToPdfRenderer object and calling the RenderDocxAsPdf method with the desired DOCX file path.

What platforms does IronPDF support for DOCX to PDF conversion?

IronPDF supports DOCX to PDF conversion on multiple platforms, including Windows, Linux, and macOS, making it versatile for different development environments.

How can developers integrate IronPDF into their existing .NET applications?

Developers can integrate IronPDF into their .NET applications by installing the IronPDF library via NuGet packages, allowing seamless conversion of DOCX to PDF with additional features like Mail Merge.

How does IronPDF enhance security in converted PDF documents?

IronPDF enhances security by allowing developers to implement features such as adding passwords or setting specific permissions on the PDF documents post conversion.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 20,756,830Version:2026.8just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.8

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.8

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required