First of all you should create a PDF document in a right way. In iText 7 youâ€™ll need:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
Now you can refer to this object to know the number of pages in the document:
Click this link if you want to see how to answer this question in iText 5.