Search in sources :

Example 11 with CompositeCleanupStrategy

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

the class PdfCleanUpToolTest method autoCleanPageTest.

@Test
public void autoCleanPageTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanPageTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanPageTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    try (PdfReader reader = new PdfReader(input);
        PdfWriter writer = new PdfWriter(output);
        PdfDocument document = new PdfDocument(reader, writer)) {
        PdfCleaner.autoSweepCleanUp(document.getPage(1), strategy);
    }
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanPageTest");
}
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 CompositeCleanupStrategy

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

the class PdfCleanUpToolTest method autoCleanWithLocationAndStreamParamsTest.

@Test
public void autoCleanWithLocationAndStreamParamsTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanWithLocationAndStreamParamsTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanWithLocationAndStreamParamsTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0, 0, 200, 100)));
    PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy, additionalLocation);
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanWithLocationAndStreamParamsTest");
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) FileOutputStream(java.io.FileOutputStream) 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 13 with CompositeCleanupStrategy

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

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

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

Aggregations

CompositeCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy)25 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)25 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)25 Test (org.junit.Test)25 RegexBasedCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy)23 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)22 PdfReader (com.itextpdf.kernel.pdf.PdfReader)22 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)20 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 CleanUpImagesCompareTool (com.itextpdf.pdfcleanup.util.CleanUpImagesCompareTool)4 ByteArrayOutputStream (com.itextpdf.io.source.ByteArrayOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 CompareTool (com.itextpdf.kernel.utils.CompareTool)2 LogMessages (com.itextpdf.test.annotations.LogMessages)1