Hi Tilman,

Thanks for the quick answer,
Inserting TIFF images in the 1.8 versions can only be done for G3 or G4 compressed images, with PDCcitt.
As far as I understand, G3 and G4 are for bitonal images. Does it mean that there is no way to insert
CMYK images in a pdf ?
Is there any reason not to allow a (in-memory) BufferedImage using a 4 components CMYK ColorSpace
to be used in PDPixelMap ?

Inserting RGB BufferedImages should work with PDPixelMap. If it doesn't in 1.8.5, this would be embarassing because I worked on that one. Please open an issue in JIRA, attach the code and the image.
OK, I tested again with your code (just replaced the new File( image ) by
an in-memory empty BufferedImage created withTYPE_4BYTE_ABGR),
I observed 3 differences (in the pdf file edited with a text editor) :
1 -
    1.8.4 :*/ColorSpace /DeviceGray*
    1.8.5*: /ColorSpace /DeviceRGB*
2 - octet streams are not the same
3 - last obj (#10) refer to a different integer (does not know what it means though)
    1.8.4
        10 0 obj
        33
        endobj
    1.8.5
        10 0 obj
        52
        endobj

Despite that 1.8.5 colorspace declaration seems more
correct, result from 1.8.4 displays correctly in Acrobat
and pdf generated wit 1.8.5 does not open.

Let me know if I can help more,

Michaël


Your source code should look somewhat like this:

            doc = new PDDocument();

            PDPage page = new PDPage();
            doc.addPage( page );

BufferedImage awtImage = ImageIO.read( new File( image ) );
                ximage = new PDPixelMap(doc, awtImage);

PDPageContentStream contentStream = new PDPageContentStream(doc, page);

            //contentStream.drawImage(ximage, 20, 20 );
// better method inspired by http://stackoverflow.com/a/22318681/535646 float scale = 1f; // reduce this value if the image is too large contentStream.drawXObject(ximage, 20, 20, ximage.getWidth()*scale, ximage.getHeight()*scale);

            contentStream.close();
            doc.save( file );

Tilman

Am 04.05.2014 12:25, schrieb Michael Michaud:
Hi,

I want to insert a cmyk image in a pdf document.
Here is what I've tried :

- Create a BufferedImage with a CMYK type ColorSpace
- Set some pixels programatically
- Insert the BufferedImage in the document with PDPixelMap
==> Throws a IllegalStateException (which is consistent with the code
which checks that ColorSpace has 1 or 3 components) :-(

I've also tried to save my BufferedImage as a Tiff with Commons Imaging,
which works fine, but If I try to include it as a PDPixelMap, I have the
same error as above, and if I compress it as a CCITT image, It converts it
to black/white. Which kind of tiff can I include in a pdf exactly ?

Finally, I had a try with PdfBox 1.8.5 (previous tests were with 1.8.4), but
with 1.8.5, inserting a RGB BufferedImage, which works fine with 1.8.4,
creates a PDF I can't open with acrobat reader :-(

Any hint about one of these problem is welcome,

Michaël






Reply via email to