Skip to main content
convert PDF to Doc

How to convert PDF to Doc in C#, VB.NET?

In this post, we will explain how to convert PDF to Doc in C#, VB.NET using Spire.PDF. Let us first understand a bit about Spire.PDF.

Spire components for .NET

Introduction to Spire.PDF

Spire.PDF for .NET is a professional PDF component applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET application. Using this .NET PDF library, you can implement rich capabilities to create PDF files from scratch or process existing PDF documents entirely through C#/VB.NET without installing Adobe Acrobat.

How to convert PDF to Doc in C#, VB.NET? #csharp #vbdotnet @eiceblue #aspnet Click To Tweet

Why use Spire.PDF?

First of all, Spire.PDF is very helpful when it comes to Rapid Application Development (RAD). In addition to simplicity & accuracy of this component, some of the advantages of using Spire.PDF are as follows:

  • Text formatting, multilingual support, text alignment etc.
  • Few lines of code and the package (Spire.PDF) handles the rest for you.
  • Pen and brush to draw shape elements, text, images into PDF documents.
  • Layers, transparent graphics, color space and bar-code creation can render to PDF documents.

Furthermore, adding to the list:

  • Both standards, PDF/A-1b and PDF/x1a:2001 Compliance can be applied.
  • Add scalar/vector images and mask and place them in designated location.
  • Table and table style are supported by Spire.PDF for .NET
  • Insert interactive elements including Annotation, action, JavaScript, attachment, bookmark with the specifying place and appearance.

Spire.PDF is compatible with ASP.NET and is called Spire.PDF for .NET. We can get the reference added for Spire.PDF from NuGet package manager.

Not sure how to add NuGet package?

Here is a post to help you – Adding references using NuGet packages

After successful installation of NuGet package, you can see the DLL references being added to your project.

To use above added references,  you can simple write:

using Spire.Pdf; //C#
Imports Spire.Pdf 'VB.NET

Adding Spire.PDF reference

Most of all, PDF files are widely used as they are convenient and safe on the Internet, while in daily work DOC files are more common in their degree of versatility and editability.

So converting PDF to DOC files manually can be a cumbersome process rather get Spire.PDF to work for you.

However, Spire.PDF handles all the heavy task by itself. As a result, you get a PDF converted to DOC within few minutes and that to writing very few lines of code.

Screenshot of PDF document:

convert PDF to doc

The Coding Part

Finally, you can realize your requirement of converting PDF to DOC in several lines of code. Here are the steps:

Step 1: Create an object of the class PdfDocument and load it by calling the method LoadFromFile.

C# Code:

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");

VB.NET Code:

Dim pdf As New PdfDocument()
pdf.LoadFromFile("test.pdf")

Step 2: Use SaveToFile method on the above-created object and set conversion target parameter as FileFormat.DOC.

C# Code:

pdf.SaveToFile("PDFtoDoc.doc", FileFormat.DOC);

VB.NET Code:

pdf.SaveToFile("PDFtoDoc.doc", FileFormat.DOC)

Step 3: Save and review.

C# Code:

System.Diagnostics.Process.Start("PDFtoDoc.doc");

VB.NET Code:

System.Diagnostics.Process.Start("PDFtoDoc.doc")

Screenshot of the converted word document:

convert PDF to Word

Entire Code:

C# Code:

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");
pdf.SaveToFile("PDFtoDoc.doc", FileFormat.DOC);
System.Diagnostics.Process.Start("PDFtoDoc.doc");

VB.NET Code:

Dim pdf As New PdfDocument()
pdf.LoadFromFile("test.pdf")
pdf.SaveToFile("PDFtoDoc.doc", FileFormat.DOC)
System.Diagnostics.Process.Start("PDFtoDoc.doc")

In conclusion, we just want to say that converting PDF to DOC was never so easy. Just four lines of code and you are done.

Here is a complete working example in C#

using System;
using System.Diagnostics;
using Spire.Pdf;

namespace PDFToDoc
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf; 
            try
            {
                pdf = new PdfDocument();

                pdf.LoadFromFile(@"D:\netcrunch.pdf");

                pdf.SaveToFile("netcrunch.doc", FileFormat.DOC);

                Process.Start("netcrunch.doc");

            }
            catch (Exception Ex)
            {
                Console.WriteLine("Error while converting PDF to Doc: " + Ex.Message);
            }
            finally
            {
                pdf = null;
            }
        }
    }
}

Isn’t it great to use Spire.PDF?

Get the Spire products you need to integrate with your application. You can buy various Spire packages as per your needs from Ice Blue from their website.

Spire components

What do you think?

Dear Readers,
If you have any questions or suggestions please feel free to email us or put your thoughts as comments below. We would love to hear from you. In addition to that, if you found this post or article useful then please share along with your friends and help them to learn.

Happy Coding!

Was this article worth reading? Share it with fellow developers too.

DotNetCrunch

DotNetCrunch is a popular blog for latest Microsoft® technologies which is aimed for beginners and intermediate level professionals.