PDF and Word are two of the most popular file formats used in our daily work. In some cases, you may need to convert PDF documents to Word. For example, when you want to make the text in a PDF document editable and searchable. This article will illustrate how to convert PDF to Word Doc or Docx in C# and VB.NET.
Installation
Spire.PDF for .NET is used here to achieve the conversion from PDF to Word. It’s a commercial library for creating, editing, converting and printing PDF documents. A free version of Spire.PDF for .NET is also available, but it should be pointed out that it’s limited to 10 pages while loading PDF files.
You can install either of them via NuGet:
Commercial version: Install-Package Spire.PDF
Free version: Install-Package FreeSpire.PDF
Convert PDF to Word Doc in C# and VB.NET
Spire.PDF offers a PdfDocument.SaveToFile(filePath, FileFormat.DOC) method for converting PDF documents to Word Doc format. The following are the detailed steps for your reference:
- Initialize an instance of PdfDocument instance.
- Load a PDF document using PdfDocument.LoadFromFile(filePath) method.
- Convert the PDF document to Word Doc format and save it to a specified path using PdfDocument.SaveToFile(filePath, FileFormat.DOC) method.
C#
using Spire.Pdf;
namespace ConvertPdfToDoc
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument instance
PdfDocument doc = new PdfDocument();
//Load the 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);
}
}
}
VB.NET
Imports Spire.Pdf
Namespace ConvertPdfToDoc
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a PdfDocument instance
Dim doc As PdfDocument = New PdfDocument()
'Load the 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)
End Sub
End Class
End Namespace
The input PDF document:
![](https://officedevblogs805426550.wordpress.com/wp-content/uploads/2022/07/pdftodoc-inputpdf.png?w=677)
The converted Doc document:
![](https://officedevblogs805426550.wordpress.com/wp-content/uploads/2022/07/pdftodoc.png?w=767)
Convert PDF to Word Docx in C# and VB.NET
You can convert PDF documents to Word Docx format using PdfDocument.SaveToFile(filePath, FileFormat.DOCX) method. The following are the detailed steps to implement this feature:
- Initialize an instance of PdfDocument instance.
- Load a PDF document using PdfDocument.LoadFromFile(filePath) method.
- Convert the PDF document to Word Doc format and save it to a specified path using PdfDocument.SaveToFile(filePath, FileFormat.DOCX) method.
C#
using Spire.Pdf;
namespace ConvertPdfToDocx
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument instance
PdfDocument doc = new PdfDocument();
//Load the PDF document
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");
//Convert PDF to Docx and save it to a specified path
doc.SaveToFile("ToDocx.docx", FileFormat.DOCX);
}
}
}
VB.NET
Imports Spire.Pdf
Namespace ConvertPdfToDocx
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a PdfDocument instance
Dim doc As PdfDocument = New PdfDocument()
'Load the PDF document
doc.LoadFromFile("C:\Users\Administrator\Desktop\sample.pdf")
'Convert PDF to Docx and save it to a specified path
doc.SaveToFile("ToDocx.docx", FileFormat.DOCX)
End Sub
End Class
End Namespace
The converted Docx document:
![](https://officedevblogs805426550.wordpress.com/wp-content/uploads/2022/07/pdftodocx.png?w=768)
Conclusion
This article demonstrates how to convert PDF documents to Word Doc or Docx format in C# and VB.NET using Spire.PDF for .NET. The library also supports many other functions, such as adding digital signatures, inserting form fields, and protecting PDF documents. If you’re interested, you can try it by yourself.