0

In my pdf file, i add images and text as below :

Image img = Image.getInstance(fileName); // type png or jpg  
document.add(img);   
Paragraph p = new Paragraph(...);  
document.add(p);

I want to convert it to DeviceCMYK mode for printing. But in the book said : "iText doesn’t convert RGB colors into CMYK".

Then, how to solve this problem ? Must convert each img, text to CMYK color or covert all file pdf ?

I search in google and find some suggests : They use lib : Jmagic / JAI ...(ICC Color Profiles)

ICC Color Profiles : http://stackoverflow.com/questions/22298328/convert-rgb-png-to-cmyk-jpeg-using-icc-color-profiles
JAI : http://stackoverflow.com/questions/4472362/how-can-i-convert-an-rgb-image-to-cmyk-and-vice-versa-in-java

Do you have any suggestions ?

Update 1 :

My code is at below :

// PdfContentByte pdfCB = new PdfContentByte(writer);
// read buffer image (png or jpec) from link 
BufferedImage rgbImage = ImageIO.read(new URL(imageLink));
BufferedImage cmykImage = null;
ColorSpace cpace = new ICC_ColorSpace(ICC_Profile.getInstance(this.class.getClassLoader()
        .getResourceAsStream("OffsetEuroU360K85V25PO4.icc")));
ColorConvertOp op = new ColorConvertOp(rgbImage.getColorModel().getColorSpace(), cpace, null);
cmykImage = op.filter(rgbImage, null);
// write buffered image to local file
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(cmykImage, "jpg", baos);
baos.flush();
byte[] resultImageAsRawBytes = baos.toByteArray();
baos.close();
JAI.create("filestore", cmykImage, "/root/CMYK_IMAGE" + no + ".TIF", "TIFF");
// Add image to document
Image img = Image.getInstance(resultImageAsRawBytes);
// Image img = Image.getInstance(pdfCB, cmykImage, 1);
img.tagICC(com.itextpdf.text.pdf.ICC_Profile.getInstance(PBPMSItextExport.class.getClassLoader()
        .getResourceAsStream("OffsetEuroU360K85V25PO4.icc")));
document.add(img);

Result error :

java.io.IOException: The byte array is not a recognized imageformat.
com.itextpdf.text.Image.getInstance(Image.java:442)
com.itextpdf.text.Image.getInstance(Image.java:348)

But image saved in local file is CMYK color.

How to instance image of iText with input is BufferedImage ?

Link of original img in RGB : http://www.mediafire.com/view/jlbc67q5gs2l3bj/00.png

Link of img is converted and saved to local : http://www.mediafire.com/view/a8lw5yhlcww9qbm/CMYK_IMAGE3.TIF

Han Kun
  • 73
  • 12
  • As you've found, iText won't touch your images, you must provide it with the already completed images to add to the document and it will do the rest. So use those links you posted above, convert your images to CMYK remembering that the conversion is not perfect, *manually inspect each image*, and then add those images. Also, if you do anything else in the PDF make sure you are also using CMYK colors and not RGB colors. – Chris Haas Oct 01 '14 at 13:59
  • @ChrisHaas : Thank you. I also updated my code. Could you suggest for me? – Han Kun Oct 02 '14 at 12:01
  • Unfortunately I'm not a Java person but I would recommend ignoring iText for now and instead focus only on the image to CMYK. Try writing the file to disk and opening it in an image editing program like Adobe Photoshop. Once that works, then move on to adding them to a PDF. – Chris Haas Oct 02 '14 at 13:10
  • if ignores iText , everything is good. But ... – Han Kun Oct 03 '14 at 11:45
  • Can you zip up a sample image before and after so we can see them? – Chris Haas Oct 03 '14 at 13:14
  • Sorry for not replying sooner . I updated my link image. Please check it. – Han Kun Oct 05 '14 at 16:00

0 Answers0