Search in sources :

Example 16 with PdfReader

use of com.itextpdf.kernel.pdf.PdfReader 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)

Example 17 with PdfReader

use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.

the class CustomLocationExtractionStrategy method cleanUpAreaCalculationPrecisionTest.

@Test
public void cleanUpAreaCalculationPrecisionTest() throws IOException, InterruptedException {
    String input = inputPath + "cleanUpAreaCalculationPrecision.pdf";
    String output = outputPath + "cleanUpAreaCalculationPrecision.pdf";
    String cmp = inputPath + "cmp_cleanUpAreaCalculationPrecision.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
    CompareTool compareTool = new CompareTool();
    String errorMessage = compareTool.compareByContent(output, cmp, outputPath);
    Assert.assertNull(errorMessage);
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) CompareTool(com.itextpdf.kernel.utils.CompareTool) 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)

Example 18 with PdfReader

use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.

the class CustomLocationExtractionStrategy method redactIPhoneUserManualColored.

@Test
public void redactIPhoneUserManualColored() throws IOException, InterruptedException {
    String input = inputPath + "iphone_user_guide_untagged_small.pdf";
    String output = outputPath + "redactIPhoneUserManualColored.pdf";
    String cmp = inputPath + "cmp_redactIPhoneUserManualColored.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("(iphone)|(iPhone)").setRedactionColor(ColorConstants.GREEN));
    PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    // sweep
    PdfCleaner.autoSweepCleanUp(pdf, strategy);
    pdf.close();
    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)

Example 19 with PdfReader

use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.

the class CleanUpAnnotationTest method cleanUp.

private void cleanUp(String input, String output, List<PdfCleanUpLocation> cleanUpLocations) throws IOException {
    PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
    if (cleanUpLocations == null) {
        PdfCleaner.cleanUpRedactAnnotations(pdfDocument);
    } else {
        PdfCleaner.cleanUp(pdfDocument, cleanUpLocations);
    }
    pdfDocument.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 20 with PdfReader

use of com.itextpdf.kernel.pdf.PdfReader in project i7j-pdfsweep by itext.

the class CleanupLicenseEventsTest method autoCleanWithStreamParamsSendsCleanUpEventTest.

@Test
public void autoCleanWithStreamParamsSendsCleanUpEventTest() throws Exception {
    String input = INPUT_PATH + "fontCleanup.pdf";
    String output = OUTPUT_PATH + "autoCleanWithStreamParamsSendsCleanUpEventTest.pdf";
    CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
    strategy.add(new RegexBasedCleanupStrategy("leonard"));
    PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy);
    List<ConfirmEvent> events = handler.getEvents();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(0).getEvent().getEventType());
    try (PdfDocument outDoc = new PdfDocument(new PdfReader(output));
        PdfDocument inputDoc = new PdfDocument(new PdfReader(input))) {
        String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCleanUpEvent() }, inputDoc.getDocumentInfo().getProducer());
        Assert.assertEquals(expectedProdLine, outDoc.getDocumentInfo().getProducer());
    }
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) FileOutputStream(java.io.FileOutputStream) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) PdfReader(com.itextpdf.kernel.pdf.PdfReader) FileInputStream(java.io.FileInputStream) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)64 PdfReader (com.itextpdf.kernel.pdf.PdfReader)64 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)56 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)43 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)43 Test (org.junit.Test)43 Rectangle (com.itextpdf.kernel.geom.Rectangle)22 CompositeCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy)22 RegexBasedCleanupStrategy (com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy)20 PdfString (com.itextpdf.kernel.pdf.PdfString)13 ConfirmEvent (com.itextpdf.commons.actions.confirmations.ConfirmEvent)11 ArrayList (java.util.ArrayList)11 ByteArrayOutputStream (com.itextpdf.io.source.ByteArrayOutputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 CleanUpImagesCompareTool (com.itextpdf.pdfcleanup.util.CleanUpImagesCompareTool)7 CompareTool (com.itextpdf.kernel.utils.CompareTool)5 Document (com.itextpdf.layout.Document)5 PdfAutoSweepTools (com.itextpdf.pdfcleanup.autosweep.PdfAutoSweepTools)5 PdfCleanUpLocation (com.itextpdf.pdfcleanup.PdfCleanUpLocation)4 FileInputStream (java.io.FileInputStream)4