If i save a uploaded pdf file it throws a corrupted format msg.Thing is if i remove below code string resumetext = ParsePdf(resumedoc.PostedFile.InputStream); Pdf file is saved perfectly.I can open it. if i add the above code Pdf file is saved as a corrupted format.
I can read the text perfectly in both conditions.Please help me to sort out the issue.
string ext = System.IO.Path.GetExtension(FileUp.PostedFile.FileName);
if (ext == ".pdf")
{
//resumedoc is input type='file'
string resumetext = ParsePdf(resumedoc.PostedFile.InputStream);
string Filename = "dddd" + ext;
string FilePath = "E:\\temp\\" + Filename;
FileUp.PostedFile.SaveAs(FilePath);//Problem arises only here
Response.Write("Uploaded");
}
public string ParsePdf(Stream inFileName)
{
StringBuilder text = new StringBuilder();
PdfReader pdfReader = new PdfReader(inFileName);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
try
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
//ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
text.Append(System.Environment.NewLine);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
catch { }
}
return text.ToString();
}