Search in sources :

Example 1 with ByteArrayOutputStream

use of com.itextpdf.io.source.ByteArrayOutputStream in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsWithAdditionalLocationSendsCoreAndCleanUpEventTest.

@Test
public void cleanUpRedactAnnotationsWithAdditionalLocationSendsCoreAndCleanUpEventTest() 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 = new ArrayList<PdfCleanUpLocation>();
    PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30), ColorConstants.GREEN);
    cleanUpLocations.add(lineLoc);
    PdfCleaner.cleanUpRedactAnnotations(document, cleanUpLocations);
    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) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) 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 2 with ByteArrayOutputStream

use of com.itextpdf.io.source.ByteArrayOutputStream in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsSendsCoreAndCleanUpEventTest.

@Test
public void cleanUpRedactAnnotationsSendsCoreAndCleanUpEventTest() 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 = new ArrayList<PdfCleanUpLocation>();
    PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30), ColorConstants.GREEN);
    cleanUpLocations.add(lineLoc);
    PdfCleaner.cleanUpRedactAnnotations(document, 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) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 3 with ByteArrayOutputStream

use of com.itextpdf.io.source.ByteArrayOutputStream in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method autoSweepCleanUpSendsCoreAndCleanUpEventsTest.

@Test
public void autoSweepCleanUpSendsCoreAndCleanUpEventsTest() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"), new PdfWriter(baos));
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    PdfCleaner.autoSweepCleanUp(document, strategy);
    String oldProducer = document.getDocumentInfo().getProducer();
    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) RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) 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 4 with ByteArrayOutputStream

use of com.itextpdf.io.source.ByteArrayOutputStream in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method openDocumentAndCleanUpSendsCoreAndCleanUpEventsTest.

@Test
public void openDocumentAndCleanUpSendsCoreAndCleanUpEventsTest() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "page229.pdf"), new PdfWriter(baos));
    String oldProducer = document.getDocumentInfo().getProducer();
    List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
    PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30), ColorConstants.GREEN);
    cleanUpLocations.add(lineLoc);
    PdfCleaner.cleanUp(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) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 5 with ByteArrayOutputStream

use of com.itextpdf.io.source.ByteArrayOutputStream in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method autoSweepTentativeCleanUpSendsCoreEventTest.

@Test
public void autoSweepTentativeCleanUpSendsCoreEventTest() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"), new PdfWriter(baos));
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
    autoSweep.tentativeCleanUp(document);
    String oldProducer = document.getDocumentInfo().getProducer();
    document.close();
    List<ConfirmEvent> events = handler.getEvents();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(ITextCoreProductEvent.PROCESS_PDF, events.get(0).getEvent().getEventType());
    try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())))) {
        String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCoreEvent() }, oldProducer);
        Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfAutoSweepTools(com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) 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)

Aggregations

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