pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Inserting CMYK image
Date Sun, 04 May 2014 10:45:43 GMT
Hello Michaël,

Inserting TIFF images in the 1.8 versions can only be done for G3 or G4 
compressed images, with PDCcitt.

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.

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
>
>
>


Mime
View raw message