use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method cleanUpWithStreamArgumentsSendsCleanUpEventTest.
@Test
public void cleanUpWithStreamArgumentsSendsCleanUpEventTest() throws Exception {
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30));
cleanUpLocations.add(lineLoc);
String in = INPUT_PATH + "page229.pdf";
String out = OUTPUT_PATH + "cleanUpWithStreamArgumentTest.pdf";
InputStream file = new FileInputStream(in);
OutputStream output = new FileOutputStream(out);
PdfCleaner.cleanUp(file, output, cleanUpLocations, new CleanUpProperties());
List<ConfirmEvent> events = handler.getEvents();
Assert.assertEquals(1, events.size());
Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(0).getEvent().getEventType());
try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(out));
PdfDocument inputDoc = new PdfDocument(new PdfReader(in))) {
String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCleanUpEvent() }, inputDoc.getDocumentInfo().getProducer());
Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
}
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method openDocumentAndCleanUpSendsCoreAndCleanUpEventsTest.
@Test
public void openDocumentAndCleanUpSendsCoreAndCleanUpEventsTest() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "page229.pdf"), new PdfWriter(baos));
String oldProducer = document.getDocumentInfo().getProducer();
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30), ColorConstants.GREEN);
cleanUpLocations.add(lineLoc);
PdfCleaner.cleanUp(document, cleanUpLocations, new CleanUpProperties());
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());
}
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method autoCleanWithLocationAndStreamParamsSendsCleanUpEventTest.
@Test
public void autoCleanWithLocationAndStreamParamsSendsCleanUpEventTest() throws Exception {
String input = INPUT_PATH + "fontCleanup.pdf";
String output = OUTPUT_PATH + "autoCleanWithLocationAndStreamParamsSendsCleanUpEventTest.pdf";
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("leonard"));
List<PdfCleanUpLocation> additionalLocation = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(150, 650, 0, 0)));
PdfCleaner.autoSweepCleanUp(new FileInputStream(input), new FileOutputStream(output), strategy, additionalLocation);
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());
}
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheTest02.
@Test
public void filteredImagesCacheTest02() throws IOException, InterruptedException {
// reusing when several clean areas (different on different pages)
String input = inputPath + "multipleImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheTest02.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheTest02.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<>();
for (int i = 0; i < pdfDocument.getNumberOfPages(); i += 5) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 450, 300, 40)));
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(300, 400, 50, 150)));
}
for (int i = 1; i < pdfDocument.getNumberOfPages(); i += 5) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 450, 300, 20)));
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 490, 300, 20)));
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 530, 300, 20)));
}
for (int i = 3; i < pdfDocument.getNumberOfPages(); i += 5) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(300, 400, 50, 150)));
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 400, 50, 150)));
}
for (int i = 4; i < pdfDocument.getNumberOfPages(); i += 5) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 450, 300, 20)));
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 450, 300, 20)));
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(350, 450, 300, 20)));
}
cleanUp(pdfDocument, cleanUpLocations);
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 5);
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class PdfCleanUpToolTest method cleanUpTest38.
@Test
public void cleanUpTest38() throws IOException, InterruptedException {
String input = INPUT_PATH + "helloHelvetica02.pdf";
String output = OUTPUT_PATH + "helloHelvetica02.pdf";
String cmp = INPUT_PATH + "cmp_helloHelvetica02.pdf";
List<PdfCleanUpLocation> cleanUpLocations = Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(0f, 0f, 0f, 0f), ColorConstants.GRAY));
cleanUp(input, output, cleanUpLocations);
compareByContent(cmp, output, OUTPUT_PATH, "diff_38");
}
Aggregations