I want to search particular text from PDF file, if PDF Contains Image or Paragraph i want search text from both Image and Paragraph too. and show it on view, How i can achieve this.
I have following code from another source, but i don't know weather it is searching text in image or not.
string file = Server.MapPath("~/images/OoPdfFormExample.pdf");
if (System.IO.File.Exists(file))
{
string searchText = txtSearh.Text.Trim();
string currentText = string.Empty;
System.Text.StringBuilder pdfText = new System.Text.StringBuilder();
iTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(file);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = System.Text.Encoding.UTF8.GetString(Encoding.Convert (Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)));
pdfText.Append(currentText);
}
pdfReader.Close();
List<string> lines = new List<string>();
lines = pdfText.ToString().Trim().Split(' ').ToList();
List<string> matchedWord = new List<string>();
foreach (string item in lines)
{
if (!string.IsNullOrEmpty(item))
{
if (item.ToUpper().Contains(searchText.ToUpper()))
{
matchedWord.Add(item);
}
}
}
}
can somebody help ??