Thursday, January 12, 2017

Read data from PDF in c#

Festally download iTextSharp dll” this link "https://sourceforge.net/projects/itextsharp/when download dll then add reference of dll in your application after that use blow code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.Text;

namespace ReadDataFromPdf
{
    public partial class ReadPdf : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(@"C:\Users\Ankur\Downloads\PAYSLIP_APP-135_December_2016.pdf");
            StringBuilder sb = new StringBuilder();
            for(int i=1;i<= reader.NumberOfPages;i++)
            {
                sb.Append(PdfTextExtractor.GetTextFromPage(reader, i));
            }
            TextBox1.Text = sb.ToString();
            reader.Close();
        }
    }
}

No comments:

Post a Comment