Convert Word Document to PDF using Spire.Doc

I have recently been working on a project in which I must provide the ability to convert a Word Document to a PDF. I searched a lot and found Spire.Doc (a product of the e-iceblue company that provides .NET, Silverlight and WPF development components).
 
Spire.Doc for .NET is a professional Word. NET library specially designed for developers to create, read, write, convert and print Word document files from any .NET (C#, VB.NET, ASP.NET) platform with fast and high-quality performance.
 
You can also download a free edition of Spire.Doc. Free Spire.Doc for .NET is a Community Edition of the Spire.Doc for .NET, that is a totally free word component for commercial and personal use with some limitations.

 
I have downloaded Spire.Office that includes Spire.Doc as well as other components (Spire XLS, Spire.Presentation, Spire.PDF, Spire.DataExport, Spire.PDFViewer, Spire.DocViewer and Spire.BarCode). You can also download Spire.Office or Spire.Doc depending on your needs.
 
After downloading, install the Spire.Office or Spire.Doc (whatever you have downloaded). 


Let's Begin

Create a new Windows Form Application. I selected .NET Framework 4

 

Right-click on References in Solution Explorer and click Add Reference...

 

In Reference Manager, Click the Browse tab.


Now go to C:\Program Files (x86)\e-iceblue\Spire.Office\Bin\NET4.0 and Add Spire.Doc.dll to your project. 

 
 
 

After adding you will see a Spire.Doc DLL reference added to your project.

 

Now, drop a button (named btnConvert) control on the form and double-click on it to create its Click event. 
 

Add the Spire.Doc and Spire.Doc.Documents namespaces in the .cs code.

 
Add the following lines of code for the button Click event:
  1. private void btnConvert_Click(object sender, EventArgs e)  
  2. {  
  3.     //Load Document  
  4.     Document doc = new Document();  
  5.     //Pass path of Word Document in LoadFromFile method  
  6.     doc.LoadFromFile(@"C:\Users\Anoop Kumar Sharma\Desktop\Coding.Docx");  
  7.     //Pass Document Name and FileFormat of Document as Parameter in SaveToFile Method  
  8.     doc.SaveToFile("Convert.PDF",FileFormat.PDF);  
  9.     //Launch Document  
  10.     System.Diagnostics.Process.Start("Convert.PDF");  
  11. }  
Build and run the application. When you click on the Convert button, Coding.Docx, our Word Document, is converted into a PDF Document. You can find the converted PDF document to the Bin/Debug/ directory of your project.
 

I hope you liked this article. Thanks. 

Up Next
    Ebook Download
    View all
    Learn
    View all