Get the Number of Pages in a PDF File Using Java

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>
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("C:\\Users\\Administrator\\Desktop\\test.pdf");

//Get the number of pages in the PDF file
int pageCount = doc.getPages().getCount();

System.out.print("This PDF file contains "+pageCount+" pages");
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store