PageImageWriter { public static PDImageXObject toPDXImageObject(Source<?> source) throws TaskIOException { try { return createFromSeekableSource(source.getSeekableSource(), source.getName()); } catch (Exception e) { throw new TaskIOException("An error occurred creating PDImageXObject from file source: " + source.getName(), e); } } PageImageWriter(PDDocument document); void append(PDPage page, PDImageXObject image, Point2D position, float width, float height,
            PDExtendedGraphicsState gs, int rotation); void append(PDPage page, PDFormXObject image, Point2D position, float width, float height,
            PDExtendedGraphicsState gs, int rotation); void prepend(PDPage page, PDImageXObject image, Point2D position, float width, float height,
            PDExtendedGraphicsState gs, int rotation); void prepend(PDPage page, PDFormXObject image, Point2D position, float width, float height,
            PDExtendedGraphicsState gs, int rotation); static PDImageXObject toPDXImageObject(Source<?> source); static PDImageXObject createFromSeekableSource(SeekableSource original, String name); static SeekableSource convertTiffToJpg(SeekableSource source); static SeekableSource convertTiffToPng(SeekableSource source); static SeekableSource convertImageTo(SeekableSource source, String format);  }
@Test public void testJpeg() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(customNonPdfInput("image/large.jpg")); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertThat(result.getHeight(), is(3840)); assertThat(result.getWidth(), is(5760)); assertTrue("Original bytes should be used", IOUtils.contentEquals(result.getCOSObject().getFilteredStream(), customNonPdfInput("image/large.jpg").getSource())); }
@Test public void testPng() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(customNonPdfInput("image/draft.png")); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertThat(result.getHeight(), is(103)); assertThat(result.getWidth(), is(248)); }
@Test public void testTiffWithAlphaToPDXImageObject() throws TaskIOException { PDImageXObject result = PageImageWriter.toPDXImageObject(customNonPdfInput("image/draft.tiff")); assertThat(result.getHeight(), is(103)); }
@Test public void test_CMYK_jpeg() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(customNonPdfInput("image/cmyk.jpg")); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertThat(result.getHeight(), is(560)); assertThat(result.getWidth(), is(1400)); assertFalse("Original bytes should not be used; the image should be converted from CMYK to RGB", IOUtils.contentEquals(result.getCOSObject().getFilteredStream(), customNonPdfInput("image/cmyk.jpg").getSource())); }
@Test public void test_CMYK_jpeg_wrong_extension() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(customNonPdfInput("image/cmyk.jpg", "cmyk.png")); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertThat(result.getHeight(), is(560)); assertThat(result.getWidth(), is(1400)); assertFalse("Original bytes should not be used; the image should be converted from CMYK to RGB", IOUtils.contentEquals(result.getCOSObject().getFilteredStream(), customNonPdfInput("image/cmyk.jpg").getSource())); }
@Test public void test_Gray_ICC_png() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(customNonPdfInput("image/icc_profile_gray.png")); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertFalse("Original bytes should not be used; the image should be converted from ICC Gray to RGB", IOUtils.contentEquals(result.getCOSObject().getFilteredStream(), customNonPdfInput("image/icc_profile_gray.png").getSource())); }
@Test public void encryptedAtRestTest_stream() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(encryptedAtRest(customNonPdfInput("image/large.jpg"))); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertThat(result.getHeight(), is(3840)); assertTrue("Decrypted bytes should be used", IOUtils.contentEquals( result.getCOSObject().getFilteredStream(), customNonPdfInput("image/large.jpg").getSource() ) ); }
@Test public void encryptedAtRestTest_file() throws TaskIOException, IOException { PDImageXObject result = PageImageWriter.toPDXImageObject(encryptedAtRest(customNonPdfInputAsFileSource("image/draft.png"))); assertThat(result.getColorSpace(), is(PDDeviceRGB.INSTANCE)); assertThat(result.getHeight(), is(103)); }