How to Convert PDF to Word in C#

You will learn how to convert PDF to Word in C# in this tutorial. It explains how using C# PDF to DOCX conversion can be performed by providing the source PDF. The process of converting a PDF file to a Word document is straightforward and can be achieved with two or three lines of code. Moreover, you can use same approach in both desktop and web applications.

Steps to Convert PDF to Word in C#

  1. Install GroupDocs.Conversion for .NET from the NuGet package manager to convert PDF to Word in C#
  2. Add a reference to GroupDocs.Conversion namespace
  3. Create an instance of the Converter class and load the source PDF document for conversion
  4. Instantiate WordProcessingConvertOptions class
  5. Call the Converter class’s convert method, passing the converted document’s filename and the instance of WordProcessingConvertOptions from the previous step.

You can view PDF to Word C# example code for document conversion in the next step. Finally, the converted file is saved to disc as DOCX. Similarly, you can also convert from PDF to another Word file format by using WordProcessingFileType class and specifying document type for conversion.

Code to Convert PDF to Word in C#

using System;
using GroupDocs.Conversion.Options.Convert;
namespace ConvertPdfToWordInCSharp
{
class Program
{
public static void Main(string[] args) // Main function to convert PDF to Word using C#
{
// Remove the watermark in output Word document by adding license
string licensePath = "GroupDocs.Conversion.lic";
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License();
lic.SetLicense(licensePath);
// Load the source PDF file for conversion to Word document
var converter = new GroupDocs.Conversion.Converter("sample.pdf");
// Set the convert options for DOCX format
var options = new WordProcessingConvertOptions();
// Save converted DOCX file
converter.Convert("converted.docx", options);
Console.WriteLine("Done");
}
}
}

In this example, we have learned how to convert PDF to Word using C#. It loads the source PDF document from the disc using the Converter class object, but it can also be loaded via a stream. DOCX is the default format for PDF to Word conversion. However, it supports various formats of Microsoft Word such as DOC, DOCX, RTF and many more for conversion from PDF. In addition, EPUB, XLSX, PPTX, HTML, XML, and a variety of other formats are all supported for conversion from PDF.

 English