Tuesday, March 22, 2011

HOW TO COUNT NUMBER OF PAGES FROM PDF FILE

You need to download first itextsharp.dll file add this file to c# project through reference then type the below codes :

using iTextSharp.text.pdf; //use this at the top
 //this is function for counting pages return integer
 public int GETPDFPageCount(string filepath)
        {
            int page_count = 0;
            try
            {
                //check for the extension


                //Create instance for the PDF reader
                PdfReader pdf_fie = new PdfReader(filepath);
                //read it's pagecount
                page_count = pdf_fie.NumberOfPages;
                //close the file
                pdf_fie.Close();

            }
            catch (PdfException ex)
            {
                MessageBox.Show(ex.Message);
            }
            return page_count;
        }

download itextsharp.dll from here Download

1 comment: