Question

i want to identify a word in a PDF document and go to that page which word is available.when i search a word and click a button i want to go to that page.i used below code but i couldn't find the answer.

        public List<int> ReadPdfFile(string fileName, String searthText)
    {
        List<int> pages = new List<int>();
        if (File.Exists(fileName))
        {
            PdfReader pdfReader = new PdfReader(fileName);
            for (int page = 1; page <= pdfReader.NumberOfPages; page++)
            {
                ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();

                string currentPageText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
                if (currentPageText.Contains(searthText))
                {
                    pages.Add(page);
                }
            }
            pdfReader.Close();
        }
        return pages;

    }

i got the no of pages which the word is used by this.

        private void btnSearch_Click(object sender, EventArgs e)
    {
        String s = textBox1.Text;

        List<int> list1 = ReadPdfFile(dlg.FileName, s);
        for (int i = 0; i < list1.Count;i++ )
        {
            richTextBox2.Text = list1[i].ToString();
        }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top