iText在PDF图像中嵌入色彩空间(ICC配置文件) [英] iText embedding Color space (ICC Profile) in PDF Images

查看:182
本文介绍了iText在PDF图像中嵌入色彩空间(ICC配置文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText-7 Java库使用以下代码生成pdf. (我正在将图像添加到pdf文档)

I am using iText-7 java library to generate pdf using below code. (I am adding image to pdf doc)

 pdf = new PdfDocument(writer);
 Document document = new Document(pdf);

 ImageData data = ImageDataFactory.create(imgfilepath);

 Image img = new Image(data);
 img.scaleToFit(imageWidth, imageHeight);

 img.setFixedPosition(1, 0, 0);
 document.add(img);

-使用相同的图像,我已经从acrobat创建了PDF.

-Using same Image i have created PDF from acrobat.

问题:

(1)当我打印2张以上的PDF时-使用iText创建的1张PDF,使用Acrobat创建的2张PDF-我发现打印质量有所不同.

(1) When i print above 2 PDFs- 1 created using iText, 2- created using Acrobat - i see quality different in print.

  • 所以我做了研究,发现有一些需要绑定的相关iCC配置文件(颜色配置文件).

当我检查两个PDF的元数据时,我知道PDF的Color Space属性存在一些差异.(我已经在此处检查了元数据: https://www.metadata2go.com )

When i check metadata of both the PDFs i come to know there is some difference in Color Space property of PDF.( i have checked meta data here : https://www.metadata2go.com)

ITEXT PDF METADATA详细信息:

ITEXT PDF METADATA DETAIL:

Acrobat PDF METADATA详细信息

Acrobat PDF METADATA DETAIL

我的问题

(1)在CMYK Machine(例如indigo)中打印时,如何使用iText获得与Acrobat相同的质量?

(1) How can i get same quality like Acrobat using iText when print in CMYK Machine (ex.indigo)?

(2)有什么方法可以将色彩配置文件(色彩空间)附加到PDF中的图像? (目前我尝试过的方法似乎无效)

(2) Is There any Way to attach color profile(Color Space) to image in PDF? (currently what i have tried looks not working)

您可以在此处检查两个PDF:

You can check both PDFs Here:

(1)使用Acrobat创建的PDF
(2)使用iText创建的PDF

(1) PDF Created Using Acrobat
(2) PDF Created Using iText

这里有iText RUPS的更多信息:

Here some more information from iText RUPS:

iText生成的PDF详细信息

iText Generated PDF Details

Acrobat生成的PDF:

Acrobat Generated PDF :

推荐答案

似乎如果操纵图像,则ICC配置文件将丢失.

It seems that if the image is manipulated, the ICC profile is lost.

我使用PdfCanvas api将iPhone拍摄的图像添加到PDF中,对我来说很好.

I used the PdfCanvas api to add an image taken from iPhone to the PDF, it looks good to me.

    @Test
    public void testImageColorSpace() throws Exception {

        String imageWithIcc = resourceFile("image-ios-profile.jpg");
        String destination = targetFile("image-colorspace-itext-pdfcanvas.pdf");
        
        PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destination));
        PdfPage page = pdfDocument.addNewPage(new PageSize(mm2pt(400f), mm2pt(400f)));

        PdfCanvas pdfCanvas = new PdfCanvas(page);
        
        ImageData imageData = ImageDataFactory.create(imageWithIcc);

        AffineTransform at = AffineTransform.getTranslateInstance(mm2pt(100f), mm2pt(100f));
        at.concatenate(AffineTransform.getScaleInstance(mm2pt(200f), mm2pt(200f)));
        float[] matrix = new float[6];
        at.getMatrix(matrix);

        pdfCanvas.addImage(imageData, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
        pdfDocument.close();
    }

这篇关于iText在PDF图像中嵌入色彩空间(ICC配置文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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