Convert PDF to Word document using C# and VB.Net in ASP.Net

KatieNgoc
 
on Nov 12, 2019 11:45 PM
Sample_489223.zip
6938 Views

Hello,

How to convert PDF file to word in ASP.Net and C#?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Nov 13, 2019 03:13 AM
on May 24, 2022 02:38 AM

Hi KatieNgoc,

Check this example.

Using Spire.PDF

You can use Spire.PDF library.

Install using below command with Package Manager Console.

Install-Package Spire.PDF

Code

C#

string pdfFile = Server.MapPath("~/Files/Coding.pdf");
string wordFile = Server.MapPath("~/Files/Coding.docx");
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(pdfFile);
doc.SaveToFile(wordFile, FileFormat.DOCX);

VB.Net

Dim pdfFile As String = Server.MapPath("~/Files/Test.pdf")
Dim wordFile As String = Server.MapPath("~/Files/Test.docx")
Dim doc As PdfDocument =  New PdfDocument() 
doc.LoadFromFile(pdfFile)
doc.SaveToFile(wordFile, FileFormat.DOCX)

For more details refer e-iceblue: Convert PDF to Word.

 

Using SautinSoft.PdfFocus

You can use SautinSoft.PdfFocus library.

Install using below command with Package Manager Console.

Install-Package sautinsoft.pdffocus -Version 8.4.5.25

C#

string pdfFile = Server.MapPath("~/Files/Test.pdf");
string wordFile = Server.MapPath("~/Files/Test.docx");
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.OpenPdf(pdfFile);
if (f.PageCount > 0)
{
    f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
    f.ToWord(wordFile);
}

VB.Net

Dim pdfFile As String = Server.MapPath("~/Files/Test.pdf")
Dim wordFile As String = Server.MapPath("~/Files/Test.docx")
Dim f As SautinSoft.PdfFocus = New SautinSoft.PdfFocus()
f.OpenPdf(pdfFile)
If f.PageCount > 0 Then
    f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx
    f.ToWord(wordFile)
End If

Screenshot

PDF

Word