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

Gadhi Pajabi2 reputationPosted Dec 3, 2015, 11:55 PM EST
Hari Ahuja2 reputationPosted Dec 10, 2015, 3:37 AM EST
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