PdfAPage extends PdfPage { @Override public void flush(boolean flushResourcesContentStreams) { if (flushResourcesContentStreams || ((PdfADocument) getDocument()).isClosing() || ((PdfADocument) getDocument()).checker.objectIsChecked(this.getPdfObject())) { super.flush(flushResourcesContentStreams); } else { ((PdfADocument) getDocument()).logThatPdfAPageFlushingWasNotPerformed(); } } PdfAPage(PdfDocument pdfDocument, PageSize pageSize);   PdfAPage(PdfDictionary pdfObject); @Override void flush(boolean flushResourcesContentStreams);  }
@Test @LogMessages(messages = {@LogMessage(messageTemplate = PdfALogMessageConstant.PDFA_PAGE_FLUSHING_WAS_NOT_PERFORMED)}) public void checkThatFlushingPreventedWithFalseFlushResourcesContentStreams() throws IOException { String outPdf = destinationFolder + "checkThatFlushingPreventedWithFalseFlushResourcesContentStreams.pdf"; PdfWriter writer = new PdfWriter(outPdf); PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "", "http: new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm"))); pdfDoc.setTagged(); pdfDoc.getCatalog().setLang(new PdfString("en-US")); EndPageEventHandler eventHandler = new EndPageEventHandler(); pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, eventHandler); int pageCount = 3; for (int i = 0; i < pageCount; i++) { pdfDoc.addNewPage().flush(false); } Assert.assertEquals(pageCount, pdfDoc.getNumberOfPages()); Assert.assertEquals(0, eventHandler.getCounter()); pdfDoc.close(); Assert.assertEquals(pageCount, eventHandler.getCounter()); Assert.assertNull(new VeraPdfValidator().validate(outPdf)); }
@Test public void checkFlushingWithTrueFlushResourcesContentStreams() throws IOException { String outPdf = destinationFolder + "checkFlushingWithTrueFlushResourcesContentStreams.pdf"; PdfWriter writer = new PdfWriter(outPdf); PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "", "http: new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm"))); pdfDoc.setTagged(); pdfDoc.getCatalog().setLang(new PdfString("en-US")); EndPageEventHandler eventHandler = new EndPageEventHandler(); pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, eventHandler); int pageCount = 3; for (int i = 0; i < pageCount; i++) { pdfDoc.addNewPage().flush(true); } Assert.assertEquals(pageCount, pdfDoc.getNumberOfPages()); Assert.assertEquals(pageCount, eventHandler.getCounter()); pdfDoc.close(); Assert.assertEquals(pageCount, eventHandler.getCounter()); Assert.assertNull(new VeraPdfValidator().validate(outPdf)); }
@Test public void checkFlushingOfCheckedPage() throws IOException { String outPdf = destinationFolder + "checkFlushingOfCheckedPage.pdf"; PdfWriter writer = new PdfWriter(outPdf); PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "", "http: new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm"))); pdfDoc.setTagged(); pdfDoc.getCatalog().setLang(new PdfString("en-US")); EndPageEventHandler eventHandler = new EndPageEventHandler(); pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, eventHandler); int pageCount = 3; for (int i = 0; i < pageCount; i++) { PdfPage page = pdfDoc.addNewPage(); pdfDoc.checker.checkSinglePage(page); page.flush(false); } Assert.assertEquals(pageCount, pdfDoc.getNumberOfPages()); Assert.assertEquals(pageCount, eventHandler.getCounter()); pdfDoc.close(); Assert.assertEquals(pageCount, eventHandler.getCounter()); Assert.assertNull(new VeraPdfValidator().validate(outPdf)); }