Search in sources :

Example 11 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method redactLipsum.

@Test
public void redactLipsum() throws IOException, InterruptedException {
    String input = INPUT_PATH + "Lipsum.pdf";
    String output = OUTPUT_PATH + "cleanUpDocument.pdf";
    String cmp = INPUT_PATH + "cmp_cleanUpDocument.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(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_cleanUpDocument_");
}
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)

Example 12 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method autoCleanPageWithAdditionalLocationTest.

@Test
public void autoCleanPageWithAdditionalLocationTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanPageWithAdditionalLocationTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanPageWithAdditionalLocationTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 200, 100), ColorConstants.RED));
    try (PdfReader reader = new PdfReader(input);
        PdfWriter writer = new PdfWriter(output);
        PdfDocument document = new PdfDocument(reader, writer)) {
        PdfCleaner.autoSweepCleanUp(document.getPage(1), strategy, additionalLocation);
    }
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanPageWithAdditionalLocationTest");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) Rectangle(com.itextpdf.kernel.geom.Rectangle) 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)

Example 13 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method autoCleanWithCleaUpPropertiesTest.

@Test
public void autoCleanWithCleaUpPropertiesTest() throws Exception {
    String input = INPUT_PATH + "absentICentry.pdf";
    String output = OUTPUT_PATH + "autoCleanWithCleaUpPropertiesTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanWithCleaUpPropertiesTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = new ArrayList<>();
    additionalLocation.add(new PdfCleanUpLocation(1, new Rectangle(100, 100, 500, 500)));
    PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy, additionalLocation, new CleanUpProperties());
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanWithCleaUpPropertiesTest");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfString(com.itextpdf.kernel.pdf.PdfString) FileInputStream(java.io.FileInputStream) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 14 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method autoCleanPageWithAdditionalLocationAndPropertyTest.

@Test
public void autoCleanPageWithAdditionalLocationAndPropertyTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanPageWithAdditionalLocationAndPropertyTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanPageWithAdditionalLocationAndPropertyTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 200, 100), ColorConstants.RED));
    try (PdfReader reader = new PdfReader(input);
        PdfWriter writer = new PdfWriter(output);
        PdfDocument document = new PdfDocument(reader, writer)) {
        PdfCleaner.autoSweepCleanUp(document.getPage(1), strategy, additionalLocation, new CleanUpProperties());
    }
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanPageWithAdditionalLocationAndPropertyTest");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) Rectangle(com.itextpdf.kernel.geom.Rectangle) 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)

Example 15 with RegexBasedCleanupStrategy

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

the class CustomLocationExtractionStrategy method redactIPhoneUserManual.

@Test
public void redactIPhoneUserManual() throws IOException, InterruptedException {
    String input = inputPath + "iphone_user_guide_untagged.pdf";
    String output = outputPath + "redactIPhoneUserManual.pdf";
    String cmp = inputPath + "cmp_redactIPhoneUserManual.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(iphone)|(iPhone)"));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    // sweep
    PdfCleaner.autoSweepCleanUp(pdf, strategy);
    pdf.close();
    // compare
    CleanUpImagesCompareTool cmpTool = new CleanUpImagesCompareTool();
    String errorMessage = cmpTool.extractAndCompareImages(output, cmp, outputPath, "4");
    // TODO DEVSIX-4047 Switch to compareByContent() when the ticket will be resolved
    String compareByContentResult = cmpTool.compareVisually(output, cmp, outputPath, "diff_redactIPhoneUserManual_", cmpTool.getIgnoredImagesAreas());
    if (compareByContentResult != null) {
        errorMessage += compareByContentResult;
    }
    if (!errorMessage.equals("")) {
        Assert.fail(errorMessage);
    }
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) CleanUpImagesCompareTool(com.itextpdf.pdfcleanup.util.CleanUpImagesCompareTool) 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