how to read pdf file in asp.net using c#.net
hi friends....
i want to read .pdf file using c#.net code and have to save that file ... Below is my code ... But it reads only one page of a file. I want to read all the
pages of a file.
Anyone help me...
else if (extn.Equals(".pdf"))
{
string filePath = Server.MapPath("uploads/" + filename);
string pdfText = string.Empty;
PdfReader pdfreader = new PdfReader(filePath);
//for (int page = 1; page <= pdfreader.NumberOfPages; page++)
//{
ITextExtractionStrategy itextextStrat = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
// ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
String extractText = PdfTextExtractor.GetTextFromPage(pdfreader,i, itextextStrat);
extractText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(extractText)));
pdfText = pdfText + extractText;
// byte[] bytes = Encoding.UTF8.GetBytes("?"); //bytes now holds 0xDB8C
// byte[] converted = Encoding.Convert(Encoding.Default, Encoding.UTF8, bytes);//converted now holds 0xC39BC592
//// string final = Encoding.UTF8.GetString(converted);
// string pdftext = Encoding.UTF8.GetString(converted);
pdfreader.Close();
query = "INSERT INTO Fileupload([category],[subcategory],[uid],[oid],[up_name],[demo1],[keyword],[fdata],[aflag],sizebyte) VALUES('" + dropcategory.SelectedValue + "','" + DropDownList1.SelectedValue + "','" + Session["user_id"].ToString() + "','" + txtOwnerId.SelectedItem + "','" + fname + "','" + demo1.Text + "','" + key + "','" +pdfText+ "',1,'" + size + "') ";
//}
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();// ExecuteScalar().ToString();
}
Thanks in Advance....