Search in sources :

Example 21 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method cleanUpPageTest.

@Test
public void cleanUpPageTest() throws IOException, InterruptedException {
    String input = INPUT_PATH + "Lipsum.pdf";
    String output = OUTPUT_PATH + "cleanUpPage.pdf";
    String cmp = INPUT_PATH + "cmp_cleanUpPage.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.getPage(1), strategy);
    pdf.close();
    // compare
    compareByContent(cmp, output, OUTPUT_PATH, "diff_cleanUpPage_");
}
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 22 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method lineArtsDrawingOnCanvasTest.

@Test
@Ignore("DEVSIX-4047")
public void lineArtsDrawingOnCanvasTest() throws IOException, InterruptedException {
    String input = INPUT_PATH + "lineArtsDrawingOnCanvas.pdf";
    String output = OUTPUT_PATH + "lineArtsDrawingOnCanvas.pdf";
    String cmp = INPUT_PATH + "cmp_lineArtsDrawingOnCanvas.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(iphone)|(iPhone)"));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    PdfCleaner.autoSweepCleanUp(pdf, strategy);
    pdf.close();
    compareByContent(cmp, output, OUTPUT_PATH, "diff_lineArtsDrawingOnCanvasTest_");
}
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) Ignore(org.junit.Ignore) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 23 with RegexBasedCleanupStrategy

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

the class PdfCleanUpToolTest method autoCleanWithFalseProcessAnnotationTest.

@Test
public void autoCleanWithFalseProcessAnnotationTest() throws Exception {
    String input = INPUT_PATH + "absentICentry.pdf";
    String output = OUTPUT_PATH + "autoCleanWithFalseProcessAnnotationTest.pdf";
    String cmp = INPUT_PATH + "cmp_autoCleanWithFalseProcessAnnotationTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    List<PdfCleanUpLocation> additionalLocation = new ArrayList<>();
    additionalLocation.add(new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30)));
    CleanUpProperties properties = new CleanUpProperties();
    properties.setProcessAnnotations(false);
    PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy, additionalLocation, properties);
    compareByContent(cmp, output, OUTPUT_PATH, "autoCleanWithFalseProcessAnnotationTest");
}
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)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