This article demonstrates how to determine the number of pages in a PDF file using Spire.PDF for JAVA.
The following screenshot shows a PDF file which contains 73 pages:
Code snippets:
import com.spire.pdf.PdfDocument; public class CountPagesOfPDF { public static void main(String[] args) { //Instantiate a PdfDocument object PdfDocument doc=new PdfDocument(); //Load the PDF file doc.loadFromFile("Test.pdf"); //Get the number of pages in the PDF file int pageCount = doc.getPages().getCount(); System.out.print(pageCount); } }
Outout: