Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用pdfbox在pdf上显示CMYK图像_Java_Spring Mvc_Pdf_Pdf Generation_Pdfbox - Fatal编程技术网

Java 使用pdfbox在pdf上显示CMYK图像

Java 使用pdfbox在pdf上显示CMYK图像,java,spring-mvc,pdf,pdf-generation,pdfbox,Java,Spring Mvc,Pdf,Pdf Generation,Pdfbox,我正在尝试使用pdfbox 1.8在java中创建pdf,但问题是我无法在pdf上显示CMYK图像,所以我尝试使用以下代码解决此问题: File filePath = new File("C:/Users/msuryawanshi/Documents/10734730431625_C1LA.jpg"); JPEGImageDecoder jpegDecoder = JPEGCodec.createJPEGDecoder(new FileInputStream(filePath)); Buffer

我正在尝试使用pdfbox 1.8在java中创建pdf,但问题是我无法在pdf上显示CMYK图像,所以我尝试使用以下代码解决此问题:

File filePath = new File("C:/Users/msuryawanshi/Documents/10734730431625_C1LA.jpg");
JPEGImageDecoder jpegDecoder = JPEGCodec.createJPEGDecoder(new FileInputStream(filePath));
BufferedImage image = jpegDecoder.decodeAsBufferedImage();
imageUrl = "http://extranet.handgards.com/gs1/10734730431625_C1LA.jpg";
File f = new File("C:/Users/msuryawanshi/Documents/10734730431625_C1LA.jpg");
String url = "http://extranet.handgards.com/gs1/10734730431625_C1LA.jpg";
Iterator readers = ImageIO.getImageReadersByFormatName("JPEG");
ImageReader reader = null;
while (readers.hasNext()) {
    reader = (ImageReader) readers.next();
    if (reader.canReadRaster()) {
        break;
    }
}

//Stream the image file (the original CMYK image)
ImageInputStream input = ImageIO.createImageInputStream(f);
reader.setInput(input);
//Read the image raster
Raster raster = reader.readRaster(0, null);

//Create a new RGB image
BufferedImage bi = new BufferedImage(raster.getWidth(), raster.getHeight(),
        BufferedImage.TYPE_4BYTE_ABGR);
//Fill the new image with the old raster
bi.getRaster().setRect(raster);
PDXObjectImage ximage = new PDPixelMap(document, bi);
contentStream.drawXObject(ximage, margin + 5, texty, 170, 100);


但图像是没有意义的,我附加了输出pdf和原始图像,我想在我的pdf上显示。请提供帮助。

PDFBox根本不支持嵌入CMYK图像,因为java本身无法读取此类图像。通过使用而不是Java ImageIO将JPEG读入BuffereImage,您可以将其嵌入为RGB图像。从这里开始,只需使用PDPixelMap(1.8版)或LosslessFactory(2.0版)。

我无法从您的问题中理解您是否要嵌入CMYK版本的JPEG,无论哪种方式-在Java中处理CMYK JPEG都是棘手的。请参阅以获取可能的解决方案PDFBOX根本不支持嵌入CMYK图像。您可以通过使用twelvemonkeys库而不是Java ImageIO将其嵌入为RGB图像。您好@iddo我尝试过该解决方案,但在JpegImageParser=new JpegImageParser()时出错;(JpegImageParser无法解析为类型)ByteSource ByteSource=new ByteSourceFile(文件);ByteSource无法解析为类型,是否需要任何jar?@Tilman可能您应该将其作为答案发布。即使是负面的。毕竟,不可能有肯定的答案。@Manojkumar你应该就此联系原文章作者