Hi,
while uploading the pdf file i want to read the content of that particular pdf document. and i want to show the document in grid.
my problem is:
if the pdf document contains 5 pages means it display in grid 5 times.
and 5 th time the whole content of pdf is saved. 1 time it saved 1 page content. 2 time it save 1 and 2 page content like upto 4 pages.
BUt i want to show only one time in grid and i want to save the 5 pages content data at once.
here i am using the code to read pdf document:
else if (extn.Equals(".pdf"))
{
string filePath = Server.MapPath("uploads/" + filename);
string pdfText = string.Empty;
PdfReader pdfreader = new PdfReader(filePath);
for (int j = 1; j <= pdfreader.NumberOfPages; j++)
{
ITextExtractionStrategy itextextStrat = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
// ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
String extractText = PdfTextExtractor.GetTextFromPage(pdfreader, j, itextextStrat);
extractText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(extractText)));
pdfText = pdfText + extractText;
// byte[e] 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 + "')";
query = @"INSERT INTO Fileupload([category],[subcategory],[uid],[oid],[up_name],[demo1],[keyword],[fdata],[aflag],sizebyte)
VALUES(@category,@subcategory,@uid,@oid,@up_name,@demo1,@keyword,@fdata,1,@sizebyte) ";
SqlCommand command = new SqlCommand(query, con);
//command.CommandText = command.CommandText.ToString();
command.Parameters.AddWithValue("@category", dropcategory.SelectedValue.ToString());
command.Parameters.AddWithValue("@subcategory", DropDownList1.SelectedValue.ToString());
command.Parameters.AddWithValue("@uid", Session["user_id"].ToString());
command.Parameters.AddWithValue("@oid", txtOwnerId.SelectedItem.ToString());
command.Parameters.AddWithValue("@up_name", fname);
command.Parameters.AddWithValue("@demo1", demo1.Text);
command.Parameters.AddWithValue("@keyword", key);
command.Parameters.AddWithValue("@fdata", pdfText);
command.Parameters.AddWithValue("@sizebyte", size);
command.ExecuteNonQuery();
}
}
PLs Help me for this.
Loading
George ericPosted Jul 2, 2012, 9:37 PM
sudharsan sPosted Jul 2, 2012, 5:38 AM
while i am uploading a pdf file it saves as many times as my pdf file page.
like if i insert a pdf file which consists of 20 pages it is saved as 20 times in my db.
And also the whole content of that pdf file was saved in 20 th time.
but i want it to be saved as only one time file with whole content of the pdf (1 time) in database.
(If the pdf contains 100 pages means it is saved 100 time in my db ).
so i want to rectify the problem.
George ericPosted Jul 2, 2012, 4:32 AM
I copy your codes and it runs on my side. And I also noticed your problems and requirement, but I can't seem to guess what exact you want. Please explain it if you may, then I can figure how to help with your issue.
Best Regards