0

this is the code, I m write. so sorry truly I m a newbie in coding. I m ready to find out the number of the PDF file page that appear word"Revenue". After this to print out on the CMD. Could anyone help me? thank a lot.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;



namespace pdf26052021
{
    class Program
    {
        static void Main(string[] args)
        {
            PFD PATH = new PFD();
            List<int> x = new List<int>( PATH.ReadPdfFile(@"C:\Users\fengs\Desktop\pdf", "test.pdf", "Revenue"));
            Console.WriteLine(x);
            Console.ReadLine();
        }

    }
    class PFD 
    {
        public List<int> ReadPdfFile(string path,string fileName, String searthText)
        {
            List<int> pages = new List<int>();
            if (System.IO.File.Exists(path + @"\" + fileName))
            {
                PdfReader pdfReader = new PdfReader(path + @"\" + 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;
        }

    }
}

thank you

  • What exactly is the problem of your code? What do you expect and what do you observe instead? – mkl May 26 '21 at 17:17
  • hi mkl,I m expect to get the page number of the PDF file.but the page must be approved word/text “Revenue".when I starting debug this code I m always get “System.Collections.Generic.Toint 32” – fengsheng Teoh May 27 '21 at 00:38
  • Ah, OK, so your question essentially is *how to properly output a `List` to the `Console`. I'll get back to this later. – mkl May 27 '21 at 04:45
  • Have a look at [this answer](https://stackoverflow.com/a/52972/1729265) or probably [this one](https://stackoverflow.com/a/52940/1729265) on *how to properly output a `List` to the `Console`*. Do they answer your question? – mkl May 27 '21 at 11:14
  • thank you mkl, thank you so much,i already get the right answer. i need to use @foreach to do console. – fengsheng Teoh May 27 '21 at 12:12
  • Ok, so I closed your question as duplicate of that other question. – mkl May 27 '21 at 12:25

0 Answers0