use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsWithSteamPramsSendsCleanUpEventTest.
@Test
public void cleanUpRedactAnnotationsWithSteamPramsSendsCleanUpEventTest() throws Exception {
InputStream inputStream = new FileInputStream(INPUT_PATH + "absentICentry.pdf");
OutputStream outputStream = new FileOutputStream(OUTPUT_PATH + "cleanUpRedactAnnotationsWithSteamPramsSendsCleanUpEventTest.pdf");
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
PdfCleanUpLocation lineLoc = new PdfCleanUpLocation(1, new Rectangle(100, 560, 200, 30), ColorConstants.GREEN);
cleanUpLocations.add(lineLoc);
PdfCleaner.cleanUpRedactAnnotations(inputStream, outputStream, cleanUpLocations);
List<ConfirmEvent> events = handler.getEvents();
Assert.assertEquals(1, events.size());
Assert.assertEquals(PdfSweepProductEvent.CLEANUP_PDF, events.get(0).getEvent().getEventType());
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method cleanUpRedactAnnotationsSendsCoreAndCleanUpEventTest.
@Test
public void cleanUpRedactAnnotationsSendsCoreAndCleanUpEventTest() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "absentICentry.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.cleanUpRedactAnnotations(document, 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 FilteredImagesCacheTest method filteredImagesCacheFlushingTest01.
@Test
public void filteredImagesCacheFlushingTest01() throws IOException, InterruptedException {
String input = inputPath + "severalImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheFlushingTest01.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheFlushingTest01.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
PdfCleanUpTool cleanUpTool = new PdfCleanUpTool(pdfDocument);
cleanUpTool.addCleanupLocation(new PdfCleanUpLocation(1, new Rectangle(150, 300, 300, 150)));
cleanUpTool.cleanUp();
PdfImageXObject img = pdfDocument.getPage(2).getResources().getImage(new PdfName("Im1"));
img.getPdfObject().release();
cleanUpTool.addCleanupLocation(new PdfCleanUpLocation(2, new Rectangle(150, 300, 300, 150)));
cleanUpTool.cleanUp();
cleanUpTool.addCleanupLocation(new PdfCleanUpLocation(3, new Rectangle(150, 300, 300, 150)));
cleanUpTool.cleanUp();
pdfDocument.close();
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 1);
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheTest04.
@Test
public void filteredImagesCacheTest04() throws IOException, InterruptedException {
// same image with different scaling and the same resultant image area
String input = inputPath + "multipleScaledImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheTest04.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheTest04.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<>();
float x = 559;
float y = 600.2f;
float width = 100;
float height = 100;
Rectangle region1 = new Rectangle(x - width, y - height, width, height);
float scaleFactor = 1.2f;
width *= scaleFactor;
height *= scaleFactor;
Rectangle region2 = new Rectangle(x - width, y - height, width, height);
for (int i = 0; i < pdfDocument.getNumberOfPages(); i += 2) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, region1));
cleanUpLocations.add(new PdfCleanUpLocation(i + 2, region2));
}
cleanUp(pdfDocument, cleanUpLocations);
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 1);
}
use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.
the class FilteredImagesCacheTest method filteredImagesCacheTest03.
@Test
public void filteredImagesCacheTest03() throws IOException, InterruptedException {
// same areas, different src images
String input = inputPath + "multipleDifferentImageXObjectOccurrences.pdf";
String output = outputPath + "filteredImagesCacheTest03.pdf";
String cmp = inputPath + "cmp_filteredImagesCacheTest03.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<>();
for (int i = 0; i < pdfDocument.getNumberOfPages(); ++i) {
cleanUpLocations.add(new PdfCleanUpLocation(i + 1, new Rectangle(150, 300, 300, 150)));
}
cleanUp(pdfDocument, cleanUpLocations);
compareByContent(cmp, output, outputPath, "1.2");
assertNumberXObjects(output, 2);
}
Aggregations