Search in sources :

Example 76 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class CleanUpImageIndexedColorSpaceTest method noWhiteColorTest.

@Test
public void noWhiteColorTest() throws Exception {
    String input = inputPath + "indexedImageNoWhite.pdf";
    String output = outputPath + "indexedImageNoWhite.pdf";
    String cmp = inputPath + "cmp_indexedImageNoWhite.pdf";
    try (PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output))) {
        PdfCleaner.cleanUp(pdfDocument, Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(150, 250, 100, 100))));
    }
    /*
          Result in Java and .NET is different.

          Java is able to process images with indexed colorspace same as others and
          doesn't preserve indexed colorspace. .NET requires special processing for
          indexed colorspace images, but preserves indexed colorspace.

          In .NET color of cleaned area is the first color of indexed color palette.
          In Java color of cleaned area is white.
         */
    Assert.assertNull(new CompareTool().compareByContent(output, cmp, outputPath));
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfCleanUpLocation(com.itextpdf.pdfcleanup.PdfCleanUpLocation) Rectangle(com.itextpdf.kernel.geom.Rectangle) CompareTool(com.itextpdf.kernel.utils.CompareTool) 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 77 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class CleanUpTransformedImageTest method skewedRgbImageBBoxCleanUpTest.

@Test
public void skewedRgbImageBBoxCleanUpTest() throws Exception {
    // TODO DEVSIX-5089 skewed images cleanup is not supported
    String input = inputPath + "skewedRgbImage.pdf";
    String output = outputPath + "skewedRgbImage.pdf";
    String cmp = inputPath + "cmp_skewedRgbImage.pdf";
    Rectangle cleanupRegion = new Rectangle(150, 250, 100, 100);
    cleanFirstPageAndDrawCleanupRegion(cleanupRegion, input, output);
    Assert.assertNull(findDifferencesBetweenOutputAndCmp(output, cmp));
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 78 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class CleanupImageWithColorSpaceTest method cleanUpTestColorSpaceJpegBaselineEncodedWithApp14Segment.

@Test
public void cleanUpTestColorSpaceJpegBaselineEncodedWithApp14Segment() throws Exception {
    // cleanup jpeg image with baseline encoded data and app14 segment with unknown color type
    // Adobe Photoshop will always add an APP14 segment into the resulting jpeg file.
    // To make Unknown color type we have set the quality of an image to maximum during the "save as" operation
    String input = inputPath + "imgSeparationCsJpegBaselineEncodedWithApp14Segment.pdf";
    String output = outputPath + "imgSeparationCsJpegBaselineEncodedWithApp14Segment.pdf";
    String cmp = inputPath + "cmp_imgSeparationCsJpegBaselineEncodedWithApp14Segment.pdf";
    cleanUp(input, output, Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(60f, 600f, 100f, 50f), ColorConstants.GREEN)));
    compareByContent(cmp, output, outputPath, "10");
}
Also used : PdfCleanUpLocation(com.itextpdf.pdfcleanup.PdfCleanUpLocation) Rectangle(com.itextpdf.kernel.geom.Rectangle) IntegrationTest(com.itextpdf.test.annotations.type.IntegrationTest) ExtendedITextTest(com.itextpdf.test.ExtendedITextTest) Test(org.junit.Test)

Example 79 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class CustomLocationExtractionStrategy method toRectangles.

@Override
public List<Rectangle> toRectangles(List<CharacterRenderInfo> cris) {
    Color col = ((CCharacterRenderInfo) cris.get(0)).getFillColor();
    List<Rectangle> rects = new ArrayList<>(super.toRectangles(cris));
    for (Rectangle rect : rects) {
        colorByRectangle.put(rect, col);
    }
    return rects;
}
Also used : Color(com.itextpdf.kernel.colors.Color) Rectangle(com.itextpdf.kernel.geom.Rectangle) ArrayList(java.util.ArrayList)

Example 80 with Rectangle

use of com.itextpdf.kernel.geom.Rectangle in project i7j-pdfsweep by itext.

the class BigDocumentCleanUpTest method bigUntaggedDocument.

@Test
public void bigUntaggedDocument() throws IOException, InterruptedException {
    String input = inputPath + "iphone_user_guide_untagged.pdf";
    String output = outputPath + "bigUntaggedDocument.pdf";
    String cmp = inputPath + "cmp_bigUntaggedDocument.pdf";
    List<Rectangle> rects = Arrays.asList(new Rectangle(60f, 80f, 460f, 65f), new Rectangle(300f, 370f, 215f, 260f));
    cleanUp(input, output, initLocations(rects, 130));
    compareByContent(cmp, output, outputPath, "4");
}
Also used : Rectangle(com.itextpdf.kernel.geom.Rectangle) 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