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");
}
}

--

--

--

Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automate all the things! Postman + Python + Burp macros for the win —  Part 1

Install Airflow 2 on a Raspberry Pi (using Python 3.x)

Encode Msfvenom PowerShell payload with base64

new terrain

Real World Project Management — 4 Principles

How Much Does It Cost to Hire ASP.NET Developer India?

Tech Interview Prep : Inflight Entertainment — Ruby

Rating Scale? or Story Points? or T-Shirt Sizing? & The Bias

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
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

GIT basics for beginners

Tricks and Tips to Make Debugging Easier

Class and Object

Introduction to Java Programming Environment