How to Convert PDF to Word (Doc/Docx) using C#

JonathonJonathon
2 min read

PDF is a widely used file format for sharing documents. However, sometimes we may need to convert PDF files to other formats, such as Word, for editing or other purposes. This article will share how to programmatically convert PDF to Word using a .NET PDF library.

Installation

The library in use is called Spire.PDF for .NET. To get started, we’ll need to download it via the below link or install it directly via Nuget.

https://www.e-iceblue.com/Download/download-pdf-for-net-now.html

Convert PDF to Doc/Docx in C#

The following example shows how to convert a PDF to a fixed-layout Doc or Docx document, which ensures that the resulting Word document maintains the appearance of the original PDF file to the greatest extent.

Sample C# Code:

using Spire.Pdf;

namespace ConvertPdfToFixedLayoutWord
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument pdf = new PdfDocument();

            //Load a PDF document
            pdf.LoadFromFile("C:\\Users\\Administrator\\Desktop\\input.pdf");

            //Convert the PDF to Docx
            pdf.SaveToFile("PDFToDocx.docx", FileFormat.DOCX);
            pdf.Close();
        }
    }
}

In addition, the Spire.PDF for .NET library also supports converting PDF to a flexible-structured Doc or Docx document, which makes the generated Word document easier to edit but it may look different from the original PDF file. Check the link below for a detailed tutorial.

https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Conversion/How-to-convert-PDF-to-Doc-in-C-VB.NET.html

Other Conversion Features of the .NET PDF API.

0
Subscribe to my newsletter

Read articles from Jonathon directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jonathon
Jonathon