I am working for text search and extraction from pdf using third party dll itextsharp.
I am getting the text on searching but not only that text, the whole text of that page.
I thought to use phrases or chunks so that I can get pre-and post of that text only along with it instead of whole page text. Can anyone suggest me code for phrases or anything else which I can use for it. Thanks!
My code is:
string searchText = null;
string filename = System.AppDomain.CurrentDomain.BaseDirectory;
filename = @"C:\test.pdf";
searchText = textBox.Text.ToString();
List<int> pages = new List<int>();
if (File.Exists(filename))
{
PdfReader pdfReader = new PdfReader(filename);
List<Phrase> PhraseList = new List<Phrase>();
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = SimpleTextExtractionStrategy();
string currentPageText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy)
if (currentPageText.Contains(searchText))
{
pages.Add(page);
textBox1.AppendText(PdfTextExtractor.GetTextFromPage(pdfReader, page));
textBox1.Text += pages.ToString();
}
}
pdfReader.Close();
}

Salman BegRank #284 · 8.8K reputationPosted Dec 16, 2016, 12:13 AM EST
Ritika25 reputationPosted Dec 16, 2016, 1:24 AM EST
Salman BegRank #284 · 8.8K reputationPosted Dec 16, 2016, 2:28 AM EST
{
Kip HackmanRank #2,595 · 536 reputationPosted Apr 28, 2022, 3:33 PM EDT
Leon DRank #851 · 2.6K reputationPosted Apr 28, 2022, 9:16 PM EDT