Search in sources :

Example 11 with ConfirmEvent

use of com.itextpdf.commons.actions.confirmations.ConfirmEvent in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsWithNullLocationSendsCoreAndCleanUpEventTest.

@Test
public void cleanUpRedactAnnotationsWithNullLocationSendsCoreAndCleanUpEventTest() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "absentICentry.pdf"), new PdfWriter(baos));
    String oldProducer = document.getDocumentInfo().getProducer();
    List<PdfCleanUpLocation> cleanUpLocations = null;
    PdfCleaner.cleanUpRedactAnnotations(document, cleanUpLocations, new CleanUpProperties());
    document.close();
    List<ConfirmEvent> events = handler.getEvents();
    Assert.assertEquals(2, events.size());
    Assert.assertEquals(ITextCoreProductEvent.PROCESS_PDF, events.get(0).getEvent().getEventType());
    Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(1).getEvent().getEventType());
    try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())))) {
        String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCoreEvent(), getCleanUpEvent() }, oldProducer);
        Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 12 with ConfirmEvent

use of com.itextpdf.commons.actions.confirmations.ConfirmEvent in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsWithStreamArgumentsSendsCleanUpEventTest.

@Test
public void cleanUpRedactAnnotationsWithStreamArgumentsSendsCleanUpEventTest() throws Exception {
    String in = INPUT_PATH + "absentICentry.pdf";
    String out = OUTPUT_PATH + "cleanUpRedactAnnotationsWithStreamArgumentTest.pdf";
    InputStream file = new FileInputStream(in);
    OutputStream output = new FileOutputStream(out);
    PdfCleaner.cleanUpRedactAnnotations(file, output);
    List<ConfirmEvent> events = handler.getEvents();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(0).getEvent().getEventType());
    try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(out));
        PdfDocument inputDoc = new PdfDocument(new PdfReader(in))) {
        String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCleanUpEvent() }, inputDoc.getDocumentInfo().getProducer());
        Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) PdfReader(com.itextpdf.kernel.pdf.PdfReader) FileInputStream(java.io.FileInputStream) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Aggregations

ConfirmEvent (com.itextpdf.commons.actions.confirmations.ConfirmEvent)12 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)12 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)12 Test (org.junit.Test)12 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)11 PdfReader (com.itextpdf.kernel.pdf.PdfReader)11 ByteArrayOutputStream (com.itextpdf.io.source.ByteArrayOutputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)7 Rectangle (com.itextpdf.kernel.geom.Rectangle)6 CompositeCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy)5 RegexBasedCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 PdfAutoSweepTools (com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools)2