Search in sources :

Example 11 with Rectangle

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) FileInputStream(java.io.FileInputStream) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 12 with Rectangle

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());
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) ByteArrayOutputStream(com.itextpdf.io.source.ByteArrayOutputStream) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 13 with Rectangle

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);
}
Also used : PdfImageXObject(com.itextpdf.kernel.pdf.xobject.PdfImageXObject) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfName(com.itextpdf.kernel.pdf.PdfName) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 14 with Rectangle

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);
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 15 with Rectangle

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);
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)118 ExtendedITextTest (com.itextpdf.test.ExtendedITextTest)76 IntegrationTest (com.itextpdf.test.annotations.type.IntegrationTest)76 Test (org.junit.Test)76 PdfString (com.itextpdf.kernel.pdf.PdfString)42 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)41 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)37 ArrayList (java.util.ArrayList)29 PdfReader (com.itextpdf.kernel.pdf.PdfReader)22 PdfCanvas (com.itextpdf.kernel.pdf.canvas.PdfCanvas)16 Paragraph (com.itextpdf.layout.element.Paragraph)15 PdfFont (com.itextpdf.kernel.font.PdfFont)12 Document (com.itextpdf.layout.Document)12 Canvas (com.itextpdf.layout.Canvas)11 PdfPage (com.itextpdf.kernel.pdf.PdfPage)10 ColumnDocumentRenderer (com.itextpdf.layout.ColumnDocumentRenderer)9 LogMessages (com.itextpdf.test.annotations.LogMessages)9 AreaBreak (com.itextpdf.layout.element.AreaBreak)8 PdfCleanUpLocation (com.itextpdf.pdfcleanup.PdfCleanUpLocation)8 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)7