Search in sources :

Example 1 with CompositeCleanupStrategy

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

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

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

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

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

the class CustomLocationExtractionStrategy method redactIPhoneUserManualMatchColor.

@Test
public void redactIPhoneUserManualMatchColor() throws IOException, InterruptedException {
    String input = inputPath + "iphone_user_guide_untagged.pdf";
    String output = outputPath + "redactIPhoneUserManualMatchColor.pdf";
    String cmp = inputPath + "cmp_redactIPhoneUserManualMatchColor.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new CustomLocationExtractionStrategy("(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_redactIPhoneUserManualMatchColor_", cmpTool.getIgnoredImagesAreas());
    if (compareByContentResult != null) {
        errorMessage += compareByContentResult;
    }
    if (!errorMessage.equals("")) {
        Assert.fail(errorMessage);
    }
}
Also used : 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)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