You must Sign In to post a response.
  • Category: ASP.NET

    Convert pdf to excel using C#


    I need Convert PDF file into Excel file in C#. Please let me know how to achieve it?

    I dont want to use any third party paid dll for this. Is it feasible?

    Best Regards,
    Anjali Bansal
  • #767855

    I have tried the below solution once and it worked for me.

    Kindly check this out.

    Most of them are using 3rd party tool for this. Which is simple and free too.


  • #767865

    First extract data from pdf using PdfTextExtractor.GetTextFromPage method to some object like stringbuilder like below,

    StringBuilder text = new StringBuilder();
    PdfReader pdfReader = new PdfReader(fileName);
    for (int page = 1; page <= pdfReader.NumberOfPages; page++)
    ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();
    string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
    currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)));

    once you got the result set into stringbuilder then you can export it into excel as usual, refer below link for more details.

    Hope this helps you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #768417
    try this.

    Add a reference to the "SautinSoft.PdfFocus.dll".

    using System;
    using System.IO;
    using SautinSoft;

    namespace Sample
    class Sample
    static void Main(string[] args)
    string pathToPdf = @"e:\test.pdf";
    string pathToExcel = Path.ChangeExtension(pathToPdf, ".xls");

    SautinSoft.PdfFocus pdffocus = new SautinSoft.PdfFocus();

    pdffocus.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

    // 'true' = Preserve original page layout.
    // 'false' = Place tables before text.
    pdffocus.ExcelOptions.PreservePageLayout = true;


    if (pdffocus.PageCount > 0)
    int result = pdffocus.ToExcel(pathToExcel);

    //Open a produced Excel workbook
    if (result==0)

    Software Developer
    iFour Technolab Pvt. Ltd.

  • #768418
    try this

    protected void HtmlToPdf_Click(object sender, EventArgs e)
    // create the HTML to PDF converter
    HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

    // set browser width
    htmlToPdfConverter.BrowserWidth = int.Parse(textBoxBrowserWidth.Text);

    // set browser height if specified, otherwise use the default
    if (textBoxBrowserHeight.Text.Length > 0)
    htmlToPdfConverter.BrowserHeight = int.Parse(textBoxBrowserHeight.Text);

    // set HTML Load timeout
    htmlToPdfConverter.HtmlLoadedTimeout = int.Parse(textBoxLoadHtmlTimeout.Text);

    // set PDF page size and orientation
    htmlToPdfConverter.Document.PageSize = GetSelectedPageSize();
    htmlToPdfConverter.Document.PageOrientation = GetSelectedPageOrientation();

    // set PDF page margins
    htmlToPdfConverter.Document.Margins = new PdfMargins(0);

    // set a wait time before starting the conversion
    htmlToPdfConverter.WaitBeforeConvert = int.Parse(textBoxWaitTime.Text);

    // convert HTML to PDF
    byte[] pdfBuffer = null;

    if (radioButtonConvertUrl.Checked)
    // convert URL to a PDF memory buffer
    string url = textBoxUrl.Text;

    pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
    // convert HTML code
    string htmlCode = textBoxHtmlCode.Text;
    string baseUrl = textBoxBaseUrl.Text;

    // convert HTML code to a PDF memory buffer
    pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlCode, baseUrl);

    // inform the browser about the binary data format
    HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

    // instruct browser how to open PDF as attachment or inline and file name
    String.Format("{0}; filename=HtmlToPdf.pdf; size={1}",
    checkBoxOpenInline.Checked ? "inline" : "attachment",

    // write the PDF buffer to HTTP response

    // call End() method of HTTP response to stop ASP.NET page processing

    Software Developer
    iFour Technolab Pvt. Ltd.

  • Sign In to post your comments