Search in sources :

Example 1 with RegexBasedCleanupStrategy

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

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

the class PdfAutoSweepToolsTest method highlightTest.

@Test
public void highlightTest() throws IOException, InterruptedException {
    String input = INPUT_PATH + "Lipsum.pdf";
    String output = OUTPUT_PATH + "highlightTest.pdf";
    String cmp = INPUT_PATH + "cmp_highlightTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(D|d)olor").setRedactionColor(ColorConstants.GREEN));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output).setCompressionLevel(CompressionConstants.NO_COMPRESSION));
    // sweep
    PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
    autoSweep.highlight(pdf);
    pdf.close();
    // compare
    compareByContent(cmp, output, OUTPUT_PATH, "diff_highlightTest_");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfAutoSweepTools(com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) 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 3 with RegexBasedCleanupStrategy

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

the class PdfAutoSweepToolsTest method getPdfCleanUpLocationsTest.

@Test
public void getPdfCleanUpLocationsTest() throws IOException {
    String input = INPUT_PATH + "Lipsum.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(D|d)olor"));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(new ByteArrayOutputStream()));
    // sweep
    List cleanUpLocations = (List) new PdfAutoSweepTools(strategy).getPdfCleanUpLocations(pdf.getPage(1));
    pdf.close();
    // compare
    Assert.assertEquals(2, cleanUpLocations.size());
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfAutoSweepTools(com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) List(java.util.List) PdfReader(com.itextpdf.kernel.pdf.PdfReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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 RegexBasedCleanupStrategy

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

the class PdfAutoSweepToolsTest method tentativeCleanUpTest.

@Test
public void tentativeCleanUpTest() throws IOException, InterruptedException {
    String input = INPUT_PATH + "Lipsum.pdf";
    String output = OUTPUT_PATH + "tentativeCleanUp.pdf";
    String cmp = INPUT_PATH + "cmp_tentativeCleanUp.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(D|d)olor").setRedactionColor(ColorConstants.GREEN));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output).setCompressionLevel(0));
    // sweep
    PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
    autoSweep.tentativeCleanUp(pdf);
    pdf.close();
    // compare
    compareByContent(cmp, output, OUTPUT_PATH, "diff_tentativeCleanUp_");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfAutoSweepTools(com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) 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 5 with RegexBasedCleanupStrategy

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

the class CustomLocationExtractionStrategy method redactTonySoprano.

@Test
public void redactTonySoprano() throws IOException, InterruptedException {
    String input = inputPath + "TheSopranos.pdf";
    String output = outputPath + "redactTonySoprano.pdf";
    String cmp = inputPath + "cmp_redactTonySoprano.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("Tony( |_)Soprano"));
    strategy.add(new RegexBasedCleanupStrategy("Soprano"));
    strategy.add(new RegexBasedCleanupStrategy("Sopranos"));
    PdfWriter writer = new PdfWriter(output);
    writer.setCompressionLevel(0);
    PdfDocument pdf = new PdfDocument(new PdfReader(input), writer);
    // sweep
    PdfCleaner.autoSweepCleanUp(pdf, strategy);
    pdf.close();
    // compare
    compareResults(cmp, output, outputPath, "4");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) 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