iText embedding Color space (ICC Profile) in PDF Images

后端 未结 1 760
有刺的猬
有刺的猬 2021-01-25 03:46

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 Docume         


        
相关标签:
1条回答
  • 2021-01-25 04:13

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

    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();
        }
    

    0 讨论(0)
提交回复
热议问题