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(); } }
No comments:
Post a Comment