use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy 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_");
}
use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy 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");
}
use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy 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");
}
use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy in project i7j-pdfsweep by itext.
the class PdfCleanUpToolTest method autoCleanPageWithAdditionalLocationAndPropertyTest.
@Test
public void autoCleanPageWithAdditionalLocationAndPropertyTest() throws Exception {
String input = INPUT_PATH + "fontCleanup.pdf";
String output = OUTPUT_PATH + "autoCleanPageWithAdditionalLocationAndPropertyTest.pdf";
String cmp = INPUT_PATH + "cmp_autoCleanPageWithAdditionalLocationAndPropertyTest.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, new CleanUpProperties());
}
compareByContent(cmp, output, OUTPUT_PATH, "autoCleanPageWithAdditionalLocationAndPropertyTest");
}
use of com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy in project i7j-pdfsweep by itext.
the class CustomLocationExtractionStrategy method redactIPhoneUserManual.
@Test
public void redactIPhoneUserManual() throws IOException, InterruptedException {
String input = inputPath + "iphone_user_guide_untagged.pdf";
String output = outputPath + "redactIPhoneUserManual.pdf";
String cmp = inputPath + "cmp_redactIPhoneUserManual.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("(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_redactIPhoneUserManual_", cmpTool.getIgnoredImagesAreas());
if (compareByContentResult != null) {
errorMessage += compareByContentResult;
}
if (!errorMessage.equals("")) {
Assert.fail(errorMessage);
}
}
Aggregations