Convert Word to PDF using C# Program

You may have used popular online tools to convert Word to PDF documents for projects and other documents. It is a common practice among college students as they need to submit a lot of assignments and projects to their college.

In this article, I will be showing you How you can convert Word to PDF using C# Program. It is simple and the best way to convert Word documents to PDF. For this, we will be using some additional libraries and programs in our C# Program.

Prerequisites to Convert Word to PDF using C#

To begin with the program, we first need to download two additional software as .dll files:

  1. Microsoft Office: Our C# program will be using Microsoft Office utilities for performing the conversion of Word to PDF thing. So, you must install Microsoft Office on your computer.
  2. Microsoft.Office.Interop.Word.dll: For our program to connect and use the features of Microsoft Office, we need to download the Microsoft.Office.Interop.Word.dll from the MalFreeSoft store or Nuget.

C# Program to Convert Word to PDF

Here’s the complete C# Program to Convert Word documents to PDF documents:

using Microsoft.Office.Interop.Word;
using System;
 
namespace ConsoleApp
{
    class Word2PDFProgram
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Processing File...");
            Application app = new Application();
            Document doc = app.Documents.Open(@"E:/codewin.docx");
            doc.SaveAs2(@"E:/codewin.pdf", WdSaveFormat.wdFormatPDF);
            doc.Close();
            app.Quit();
            Console.WriteLine("File Processing Completed. Document successfully converted to PDF!");
        }
    }
}

Output of Program

Here’s the output of the above C# program:

The type or namespace name ‘Office’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)

C# Compiler

Something went wrong with our compiler. If you want to contribute an output screenshot then please send us an email at [email protected] Thanks.

groot
groot

Leave a Reply

Your email address will not be published. Required fields are marked *