首页 > 解决方案 > 我无法在 pdf 中嵌入颜色空间以创建 Pdf/A

问题描述

这是我的问题,我已经用库制作了一个 java 程序,PdfBox可以从图像和其他文件中制作 pdf,pdf所以这个工作正常,但我想生成PDF/A-1. 问题是我无法嵌入色彩空间。

我已经尝试过PDFBox 给出的 CreatePDFA.java 代码

// Create output intent
InputStream colorProfile = CreatePDFA.class.getResourceAsStream("colorSpacePath");
PDOutputIntent oi = new PDOutputIntent(doc, colorProfile); 
oi.setInfo("sRGB IEC61966-2.1"); 
oi.setOutputCondition("sRGB IEC61966-2.1"); 
oi.setOutputConditionIdentifier("sRGB IEC61966-2.1"); 
oi.setRegistryName("http://www.color.org"); 
doc.getDocumentCatalog().addOutputIntent(oi);

我得到一个NullPointerException在线:
PDOutputIntent oi = new PDOutputIntent(doc, colorProfile);

例外:

Exception in thread "main" java.lang.NullPointerException
at java.desktop/java.awt.color.ICC_Profile.getProfileDataFromStream(ICC_Profile.java:1034)
at java.desktop/java.awt.color.ICC_Profile.getInstance(ICC_Profile.java:1016)
at org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent.configureOutputProfile(PDOutputIntent.java:112)
at org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent.<init>(PDOutputIntent.java:49)
at src.Kairos.CreatePDFA.doIt(CreatePDFA.java:124)
at src.Kairos.CreatePDFA.main(CreatePDFA.java:153)

标签: javapdfpdfboxpdfa

解决方案


这是有效的代码:

InputStream colorProfile = new FileInputStream(colorSpacePath);
PDOutputIntent oi = new PDOutputIntent(doc, colorProfile);
oi.setInfo("sRGB IEC61966-2.1");
oi.setOutputCondition("sRGB IEC61966-2.1");
oi.setOutputConditionIdentifier("sRGB IEC61966-2.1")
oi.setRegistryName("http://www.color.org");
doc.getDocumentCatalog().addOutputIntent(oi);
colorProfile.close()

推荐阅读