0

I need to extract the numner of pages of a pdf in c#. Actually I trying a bit with itextsharp but there only a method where i can extract the page size (the rectangle) but nothing where i can see the number of pages. Any idea?

    static void Main(string[] args)
    {
        Console.WriteLine("starting");
        String filename = "d:\\tmp\\t1.pdf";

        if (File.Exists(filename)){
            byte[] pdfFile = File.ReadAllBytes(filename);
            PdfReader reader = new PdfReader(pdfFile);

        }


    }
mihai
  • 4,592
  • 3
  • 29
  • 42
user1760663
  • 107
  • 1
  • 6

2 Answers2

2

There is a reader.NumberOfPages() method which you can us. Its a duplicate question: Determine number of pages in a PDF file

Community
  • 1
  • 1
Al Phaba
  • 6,545
  • 12
  • 51
  • 83
2

This will solve your problem:

      static void Main(string[] args)
      {
        Console.WriteLine("starting");
            String filename = "d:\\tmp\\t1.pdf";

            if (File.Exists(filename)){
                byte[] pdfFile = File.ReadAllBytes(filename);
                PdfReader reader = new PdfReader(pdfFile);
                int numberOfPages = reader.NumberOfPages;
                Console.WriteLine(numberOfPages);
            }

       }
   }
Santosh Panda
  • 7,235
  • 8
  • 43
  • 56