java - 我无法在 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)
解决方案
这是有效的代码:
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()
推荐阅读
- node.js - 为什么我在 Node.js 中收到这个奇怪的错误?
- swiftui - SwiftUI 如何从底部边缘淡出图像
- cloud - spring 反应式和 quarkus 反应式基本原理之间的性能差异
- activemq-artemis - 消息负载平衡的客户端配置
- python - 连接字符串中的 PYODBC 传递变量
- java - 在对象数组上流式传输并收集以将键作为属性和对象作为值进行映射
- java - 使用桶排序对数组进行排序
- javascript - 单击日历外部时使反应日期选择器运行
- elasticsearch - 在过滤器查询弹性搜索中使用数组匹配
- ios - Flutter Web 应用程序无法在 Iphone 6 plus 的 IOS 12.5.4 上运行