Despite the fact that PDF documents have become quite popular nowadays, it would still be beneficial to have a tool that could accurately convert PDF files to precise Word documents, maintaining the layout and font styles. Because Word documents are editable and can be used for reproduction. This article demonstrates how to convert PDF to Doc or Docx in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert PDF to Doc
The following are the steps to convert PDF to Doc using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Convert the document to a .doc format file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf; namespace ConvertPdfToDoc { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample PDF document doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf"); //Convert PDF to Doc and save it to a specified path doc.SaveToFile("ToDoc.doc", FileFormat.DOC); } } }
Convert PDF to Docx
The following are the steps to convert PDF to Docx using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Convert the document to a .docx format file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf; namespace ConvertPdfToDocx { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample PDF document doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf"); //Convert PDF to Docx and save it to a specified path doc.SaveToFile("ToDocx2.docx", FileFormat.DOCX); } } }
Convert PDF to Docx Using PS Mode
In addition to the default conversion engine, Spire.PDF provides another engine called PS mode, which you can use for the conversion. The following are the steps to convert PDF to Docx using PS mode.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Set the conversion engine to PS mode, and set the recognition mode to flow using PdfConvertOptions.SetPdfToDocOptions(bool usePsMode, bool useFlowRecognitionMode) method.
- Convert the document to a .docx format file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf; namespace ConvertPdfToDocxUsingPsMode { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample PDF document doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf"); //Use PS mode for converting PDF to Word, and set the recognition mode to flow doc.ConvertOptions.SetPdfToDocOptions(true, true); //Convert PDF to Docx and save it to a specified path doc.SaveToFile("ToDocx.docx", FileFormat.DOCX); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.