Hide Expand
Copy Code
Copy Codeprivate void button1_Click(object sender, EventArgs e)
{ Report_DatabaseEntities ef = new Report_DatabaseEntities(); OpenFileDialog ofd = new OpenFileDialog(); string filePath; ofd.Filter = "PDF Files(*.pdf)|*.PDF|ALL Files(*.*)|*.*";
if (ofd.ShowDialog() == DialogResult.OK) { filePath = ofd.FileName.ToString();
PdfReader reader = new PdfReader(filePath); string strtext = string.Empty;
try { Listtest1 = new List ();
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy(); for (int page = 1; page <= reader.NumberOfPages; page++)
{ String s = PdfTextExtractor.GetTextFromPage(reader, page, its); s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s))); strtext = strtext + s;
string[] test = strtext.Split('\n');
foreach(var n in test)
{ test1.Add(new Report_Class() {record=n});}}foreach(var sa in test1){string test2 = sa.record;string[] ssize = test2.Split(null);}}catch (Exception ex){MessageBox.Show(ex.Message);}reader.Close();MessageBox.Show("File Has been UPLOAD"); } }

Hari AhujaPosted Dec 10, 2015, 8:37 AM
http://stackoverflow.com/questions/9500728/extract-text-from-pdf-to-c-sharp
There's another article that uses LeadTools which appears to have an array of Pages which gives you the text of each page separately in document.Pages[index]:
http://www.codeproject.com/Articles/297669/How-to-Read-Write-and-Edit-PDF-Files-and-Metadata
Gadhi PajabiPosted Dec 4, 2015, 4:55 AM