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");
}
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);
}
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");
}
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();
}
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());
}
}
Aggregations