以PDF格式写入CMYK图像 [英] Write CMYK image in PDF

查看:211
本文介绍了以PDF格式写入CMYK图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将CMYK图像( java.awt.BufferedImage )添加到带有iText的Pdf文档中。

I need to add a CMYK Image (java.awt.BufferedImage) to a Pdf-Document with iText.

我正在尝试这样做:

com.lowagie.text.Image img = Image.getInstance(BufferedImage, bgColor);

这会在生成的PDF中生成RGB图像。 (我想这是一个错误,因为它只是忽略 ColorModel )。但是我可以使用:

This produces an RGB image in the resulting PDF. (and I suppose it's a bug, because it just ignores ColorModel). However I could use:

com.lowagie.text.Image img = Image.getInstance(byte[] rawData);

并以PDF格式生成正确的CMYK-Image。但是对于第二种情况,我需要在 ByteArray 中转换 java.awt.BufferedImage 。我不能用 ImageIO.write(ByteArrayOutputStream)来做。我也不能用 com.sun.image.codec.jpeg.JPEGImageEncoder 来做,因为我必须使用 OpenJDK

And it produces a correct CMYK-Image in PDF. But for the second case I need to convert java.awt.BufferedImage in ByteArray. I cannot do it with ImageIO.write(ByteArrayOutputStream). I also cannot do it with com.sun.image.codec.jpeg.JPEGImageEncoder because I must use OpenJDK.

如何使用iText以PDF格式编写CMYK图像的正确行为?

Any ideas how can I achieve the correct behavior to write a CMYK image in PDF using iText?

推荐答案

所以基本上你要问的是如何将 BufferedImage 转换为 byte [] 打印到PDF?

So basically what you're asking is how to convert a BufferedImage to a byte[] to print to PDF?

BufferedImage img; // your image to be printed
String formatName; // name of the image format (see ImageIO docs)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( img, formatName, baos);
byte[] rawData = baos.toByteArray();

您应该可以像原始帖子一样使用CMYK图像:

You should be able to use that for the CMYK-image as you had in your original post:

com.lowagie.text.Image img = Image.getInstance(byte[] rawData);

这篇关于以PDF格式写入CMYK图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆