PDDocumentHandler implements Closeable { public PDPage addBlankPageIfOdd(PDRectangle mediaBox) { if (document.getNumberOfPages() % 2 != 0) { return addBlankPage(mediaBox); } return null; } PDDocumentHandler(PDDocument document);  PDDocumentHandler(); void setCreatorOnPDDocument(); void setDocumentInformation(PDDocumentInformation info); void setDocumentTitle(String title); PDDocumentAccessPermission getPermissions(); void setPageLayoutOnDocument(PdfPageLayout layout); void setPageModeOnDocument(PdfPageMode mode); void setPageLabelsOnDocument(Map<Integer, PdfPageLabel> labels); void setVersionOnPDDocument(PdfVersion version); void addWriteOption(WriteOption... opts); void removeWriteOption(WriteOption... opts); void setCompress(boolean compress); PDViewerPreferences getViewerPreferences(); void setViewerPreferences(PDViewerPreferences preferences); @Override void close(); void savePDDocument(File file, EncryptionAtRestPolicy encryptionAtRestSecurity); void savePDDocument(File file, StandardSecurity security, EncryptionAtRestPolicy encryptionAtRestSecurity); int getNumberOfPages(); PDDocument getUnderlyingPDDocument(); PDDocumentCatalog catalog(); PDPage importPage(PDPage page); PDPage addPage(PDPage page); void removePage(int pageNumber); void movePageToDocumentEnd(int oldPageNumber); PDPage getPage(int pageNumber); PDPageTree getPages(); void initialiseBasedOn(PDDocument other); BufferedImage renderImage(int pageNumber, int dpi, ImageColorType type); void setDocumentOutline(PDDocumentOutline outline); void setDocumentAcroForm(PDAcroForm acroForm); PDPage addBlankPageIfOdd(PDRectangle mediaBox); PDPage addBlankPage(PDRectangle mediaBox); PDPage addBlankPageAfter(int pageNumber); PDPage addBlankPageBefore(int pageNumber); static final String SAMBOX_USE_ASYNC_WRITER; }
@Test public void testAddBlankPageIfOdd() throws IOException { try (PDDocumentHandler handler = new PDDocumentHandler()) { assertNull(handler.addBlankPageIfOdd(new PDRectangle(10, 10))); handler.addBlankPage(new PDRectangle(10, 10)); assertNotNull(handler.addBlankPageIfOdd(new PDRectangle(10, 10))); } }