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 the 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 Document to PDF Document:

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 a output screenshot then please send us at email [email protected] Thanks.

Related Programs

  1. C Program to check whether the person is eligible to vote or not.
  2. C Program to input 3×3 matrix and print sum of all elements
  3. C Program for Moving Car Animation Using C Graphics
  4. C Program for Moving Car Animation Using C Graphics
  5. C Program for Bouncing Ball Animation Using C Graphics

Similar Posts

Leave a Reply

Your email address will not be published.