Convert PDF file to Word (DOCX) and save into Database in ASP.Net MVC

KatieNgoc
 
on May 16, 2022 10:55 PM
Sample_111005.zip
1386 Views

Hello, 

Can you help me to convert a PDF file to word format and save the file to SQL server using MVC and C#.

Thank you so much.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
arjunv
 
on May 17, 2022 04:47 AM
on May 17, 2022 04:47 AM

Hi KatieNgoc,

You have to download the SautinSoft.PdfFocus.dll from the below link. A sample also provided. I have created sample by referring the below solution.

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

Controller

public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        string pdfFile = Server.MapPath("~/Files/About Mudassar Khan.pdf");
        string docFileName = string.Format("{0}.docx", Path.GetFileNameWithoutExtension(pdfFile));
        string docFilePath = string.Format("~/Files/{0}.docx", Path.GetFileNameWithoutExtension(pdfFile));

        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
        f.OpenPdf(pdfFile);
        if (f.PageCount > 0)
        {
            f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
            f.ToWord(Server.MapPath(docFilePath));
        }

        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(constr))
        {
            string sql = "INSERT INTO Files (Name, FilePath) VALUES(@Name, @Path)";
            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
                cmd.Parameters.AddWithValue("@Name", docFileName);
                cmd.Parameters.AddWithValue("@Path", docFilePath);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }
        return View();
    }
}

Screenshot

PDF

Word

Database(Output)

Note: Its a trail version dll and it can process only 300 paragraphs.