Search in sources :

Example 16 with RegexBasedCleanupStrategy

use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method autoCleanWithLocationAndStreamParamsSendsCleanUpEventTest.

@Test
public void autoCleanWithLocationAndStreamParamsSendsCleanUpEventTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanWithLocationAndStreamParamsSendsCleanUpEventTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(150, 650, 0, 0)));
    PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy, additionalLocation);
    List<ConfirmEvent> events = handler.getEvents();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(0).getEvent().getEventType());
    try (PdfDocument outDoc = new PdfDocument(new PdfReader(output));
        PdfDocument inputDoc = new PdfDocument(new PdfReader(input))) {
        String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCleanUpEvent() }, inputDoc.getDocumentInfo().getProducer());
        Assert.assertEquals(expectedProdLine, outDoc.getDocumentInfo().getProducer());
    }
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) FileOutputStream(java.io.FileOutputStream) Rectangle(com.itextpdf.kernel.geom.Rectangle) 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)

Example 17 with RegexBasedCleanupStrategy

use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy 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)

Example 18 with RegexBasedCleanupStrategy

use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method autoSweepHighlightSendsCoreEventsTest.

@Test
public void autoSweepHighlightSendsCoreEventsTest() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"), new PdfWriter(baos));
    String oldProducer = document.getDocumentInfo().getProducer();
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
    autoSweep.highlight(document);
    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)

Example 19 with RegexBasedCleanupStrategy

use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy in project i7j-pdfsweep by itext.

the class PdfCleanUpToolTest method redactPdfWithNoninvertibleMatrix.

@Test
@LogMessages(messages = @LogMessage(messageTemplate = CleanUpLogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX, count = 2))
public void redactPdfWithNoninvertibleMatrix() throws IOException, InterruptedException {
    String input = INPUT_PATH + "noninvertibleMatrix.pdf";
    String output = OUTPUT_PATH + "redactPdfWithNoninvertibleMatrix.pdf";
    String cmp = INPUT_PATH + "cmp_redactPdfWithNoninvertibleMatrix.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("Hello World!").setRedactionColor(ColorConstants.GREEN));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    // sweep
    PdfCleaner.autoSweepCleanUp(pdf, strategy);
    pdf.close();
    // compare
    compareByContent(cmp, output, OUTPUT_PATH, "diff_redactPdfWithNoninvertibleMatrix_");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) PdfString(com.itextpdf.kernel.pdf.PdfString) 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) LogMessages(com.itextpdf.test.annotations.LogMessages)

Example 20 with RegexBasedCleanupStrategy

use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy in project i7j-pdfsweep by itext.

the class PdfCleanUpToolTest method redactLipsumPatternStartsWithWhiteSpace.

@Test
public void redactLipsumPatternStartsWithWhiteSpace() throws IOException, InterruptedException {
    String input = INPUT_PATH + "Lipsum.pdf";
    String output = OUTPUT_PATH + "redactLipsumPatternStartsWithWhitespace.pdf";
    String cmp = INPUT_PATH + "cmp_redactLipsumPatternStartsWithWhitespace.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("\\s(D|d)olor").setRedactionColor(ColorConstants.GREEN));
    PdfWriter writer = new PdfWriter(output);
    writer.setCompressionLevel(0);
    PdfDocument pdf = new PdfDocument(new PdfReader(input), writer);
    // sweep
    PdfCleaner.autoSweepCleanUp(pdf, strategy);
    pdf.close();
    // compare
    compareByContent(cmp, output, OUTPUT_PATH, "diff_redactLipsumPatternStartsWithWhitespace_");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) PdfString(com.itextpdf.kernel.pdf.PdfString) 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

CompositeCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy)23 RegexBasedCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy)23 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)23 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)23 Test (org.junit.Test)23 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)20 PdfReader (com.itextpdf.kernel.pdf.PdfReader)20 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)18 PdfString (com.itextpdf.kernel.pdf.PdfString)12 Rectangle (com.itextpdf.kernel.geom.Rectangle)7 ConfirmEvent (com.itextpdf.commons.actions.confirmations.ConfirmEvent)5 PdfAutoSweepTools (com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 ByteArrayOutputStream (com.itextpdf.io.source.ByteArrayOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 CleanUpImagesCompareTool (com.itextpdf.pdfcleanup.util.CleanUpImagesCompareTool)2 CompareTool (com.itextpdf.kernel.utils.CompareTool)1 LogMessages (com.itextpdf.test.annotations.LogMessages)1