gpt4 book ai didi

java - 我无法在 pdf 中嵌入颜色空间以创建 Pdf/A

转载 作者:行者123 更新时间:2023-12-02 02:50:02 25 4
gpt4 key购买 nike

这是我的问题,我用库PdfBox制作了一个java程序,从图像和其他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):

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

关于java - 我无法在 pdf 中嵌入颜色空间以创建 Pdf/A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57112757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com