public virtual void CheckThatFlushingPreventedWhenAddingElementToDocument() { // Expected log message that page flushing was not performed String outPdf = destinationFolder + "checkThatFlushingPreventedWhenAddingElementToDocument.pdf"; PdfWriter writer = new PdfWriter(outPdf); PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom" , "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm" , FileMode.Open, FileAccess.Read))); pdfDoc.SetTagged(); pdfDoc.GetCatalog().SetLang(new PdfString("en-US")); PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler(); pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler); int pageCount = 3; Document document = new Document(pdfDoc, PageSize.A4); for (int i = 1; i < pageCount; i++) { // Adding a area break causes a new page to be added and an attempt to flush the page will occur, // but flushing these pages will be prevented due to a condition added to the PdfAPage#flush method document.Add(new AreaBreak()); } // Before closing document have 3 pages, but no one call of end page event NUnit.Framework.Assert.AreEqual(pageCount, document.GetPdfDocument().GetNumberOfPages()); NUnit.Framework.Assert.AreEqual(0, eventHandler.GetCounter()); document.Close(); // During the closing event was called on each document page NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter()); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf)); }
public virtual void CheckFlushingOfCheckedPage() { String outPdf = destinationFolder + "checkFlushingOfCheckedPage.pdf"; PdfWriter writer = new PdfWriter(outPdf); PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom" , "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm" , FileMode.Open, FileAccess.Read))); pdfDoc.SetTagged(); pdfDoc.GetCatalog().SetLang(new PdfString("en-US")); PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.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); } NUnit.Framework.Assert.AreEqual(pageCount, pdfDoc.GetNumberOfPages()); NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter()); pdfDoc.Close(); NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter()); NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf)); }