我正在使用iText-7java库使用下面的代码生成pdf。(我正在将图像添加到pdf文档)
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);
-使用相同的图像,我已经创建PDF从杂技演员。
问题:
(1)当我打印以上2个PDF-1使用iText创建,2使用Acrobat创建-我看到打印质量不同。
当我检查两个PDF的元数据时,我知道PDF的颜色空间属性有些不同。(
ITEXTPDF元数据详情:
AcrobatPDFMETADATA详细信息
所以我的问题
(1)我怎么能得到相同的质量像Acrobat使用iText时打印在CMYK(ex. Indigo)?
(2)有什么方法可以将颜色配置文件(颜色空间)附加到PDF中的图像?(目前我尝试过的看起来不起作用)
您可以在此处查看这两个PDF:
(1)PDF创建使用Acrobat
(2)PDF创建使用iText
以下是来自iText RUPS的更多信息:
iText生成的PDF详细信息
似乎如果图像被操纵,ICC配置文件就会丢失。
我使用PdfCanvas api将从iPhone拍摄的图像添加到PDF,它看起来不错。
@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();
}