Search in sources :

Example 81 with Rectangle

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

Example 82 with Rectangle

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());
    }
}
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 83 with Rectangle

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());
    }
}
Also used : RegexBasedCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.RegexBasedCleanupStrategy) CompositeCleanupStrategy(com.itextpdf.pdfcleanup.autosweep.CompositeCleanupStrategy) FileOutputStream(java.io.FileOutputStream) Rectangle(com.itextpdf.kernel.geom.Rectangle) ConfirmEvent(com.itextpdf.commons.actions.confirmations.ConfirmEvent) PdfReader(com.itextpdf.kernel.pdf.PdfReader) FileInputStream(java.io.FileInputStream) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 84 with Rectangle

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);
}
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 85 with Rectangle

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");
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfString(com.itextpdf.kernel.pdf.PdfString) 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