I am working on a project and i need to read multiple pdf file from a folder and show its content when click on button. I am facing problem to read multiples files at a time. how could i read multiple pdf files.? Is anyone help me.?
protected void btnShowContent_Click(object sender, EventArgs e)
{
//if (fileUpload.HasFile)
//{
foreach (string file in Directory.GetFiles(@"E:\\Rida\","*.pdf"))
{
string str = "";
str = str + ", " + file.ToString();
PdfReader reader = new PdfReader(file);
string strPDFFile = file.ToString().Trim();
StringBuilder strPdfContent = new StringBuilder();
string pdfText = strPdfContent.ToString();
string contents = File.ReadAllText(strPDFFile);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
ITextExtractionStrategy objExtractStrategy = new SimpleTextExtractionStrategy();
string strLineText = PdfTextExtractor.GetTextFromPage(reader, i, objExtractStrategy);
strLineText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(strLineText)));
strPdfContent.Append(strLineText);
strPdfContent.Append(contents);
strPdfContent.Append("<br/>");
}
reader.Close();
lblPdfContent.Text = strPdfContent.ToString();
}
}
This line convert my pdf file content into special characters. What should i Do to avoid this conversion.?
string contents = File.ReadAllText(strPDFFile);