use of com.itextpdf.commons.actions.confirmations.ConfirmEvent 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.commons.actions.confirmations.ConfirmEvent 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.commons.actions.confirmations.ConfirmEvent 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.commons.actions.confirmations.ConfirmEvent in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method autoSweepTentativeCleanUpSendsCoreEventTest.
@Test
public void autoSweepTentativeCleanUpSendsCoreEventTest() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"), new PdfWriter(baos));
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("leonard"));
PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
autoSweep.tentativeCleanUp(document);
String oldProducer = document.getDocumentInfo().getProducer();
document.close();
List<ConfirmEvent> events = handler.getEvents();
Assert.assertEquals(1, events.size());
Assert.assertEquals(ITextCoreProductEvent.PROCESS_PDF, events.get(0).getEvent().getEventType());
try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())))) {
String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCoreEvent() }, oldProducer);
Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
}
}
use of com.itextpdf.commons.actions.confirmations.ConfirmEvent in project i7j-pdfsweep by itext.
the class CleanupLicenseEventsTest method autoSweepHighlightSendsCoreEventsTest.
@Test
public void autoSweepHighlightSendsCoreEventsTest() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"), new PdfWriter(baos));
String oldProducer = document.getDocumentInfo().getProducer();
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("leonard"));
PdfAutoSweepTools autoSweep = new PdfAutoSweepTools(strategy);
autoSweep.highlight(document);
document.close();
List<ConfirmEvent> events = handler.getEvents();
Assert.assertEquals(1, events.size());
Assert.assertEquals(ITextCoreProductEvent.PROCESS_PDF, events.get(0).getEvent().getEventType());
try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())))) {
String expectedProdLine = createExpectedProducerLine(new ConfirmedEventWrapper[] { getCoreEvent() }, oldProducer);
Assert.assertEquals(expectedProdLine, pdfDocument.getDocumentInfo().getProducer());
}
}
Aggregations