How to convert a WordDocument to PDF in C#.Net

Word Document is an essential part of any application, it may help users to prepare reports etc. You can easily create Documents programamatically using Microsoft.Office.Interop.Word Library in C#.Net.

This Library also provide capability of converting document to two another monstly used file format, PDF and XPS. Let’s beggin

Reference Library

First up all add refrence to Microsoft.Office.Interop.Word and Include to the project

Microsoft Visual Studio Reference Manager

Start Converting

using Microsoft.Office.Interop.Word;

and do the following

  • Open the File want to convert with Document constructor
  • Use ExExportAsFixedFormat to convert document into pdf
 Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
                    var wordDocument = appWord.Documents.Open("mydoc.docx");
                    wordDocument.ExportAsFixedFormat("mydoc.pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);

In the similary way you can convert document to XPS too

Ask Masrshal to realease resources

Finally we are no need to hold the Word resources , ask Marshal to release them. Do this when ever you use file resources.


Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

One thought on “How to convert a WordDocument to PDF in C#.Net”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.