Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

PDFBox: Get number of pages in PDF file

Following statements are used to get Number of pages in a PDF file.

PDDocument Pddoc = PDDocument.load(new File(fileName))
int numberOfPages = pdDoc.getNumberOfPages()



public static Optional<Integer> getNumberOfPages(String fileName) {
if (Objects.isNull(fileName)) {
throw new NullPointerException("fileName shouldn't be null");
}
try (final PDDocument pdDoc = PDDocument.load(new File(fileName))) {
return Optional.of(pdDoc.getNumberOfPages());
} catch (IOException e) {
System.out.println(e.getMessage());
return Optional.empty();
}
}




Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

PDFBox: Get number of pages in PDF file

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×