我正在尝试使用 ghost4j 0.5.0
将两个 PostScript
文件连接到一个文件,如下所示:
final PSDocument[] psDocuments = new PSDocument[2];
psDocuments[0] = new PSDocument();
psDocuments[0].load("1.ps");
psDocuments[1] = new PSDocument();
psDocuments[1].load("2.ps");
psDocuments[0].append(psDocuments[1]);
psDocuments[0].write("3.ps");
在这个简化的过程中,我收到了上述“append”行的以下异常消息:
org.ghost4j.document.DocumentException: java.lang.ClassCastException:
org.apache.xmlgraphics.ps.dsc.events.UnparsedDSCComment cannot be cast to
org.apache.xmlgraphics.ps.dsc.events.DSCCommentPage
到目前为止,我还没有找出问题所在 - 也许是某个 PostScript 文件中存在某种问题?
因此,我们将不胜感激。
编辑:
我使用 GhostScript 命令行工具进行了测试:
gswin32.exe -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile="test.ps" --filename "1.ps" "2.ps"
这会产生一个文档,其中 1.ps 和 2.ps 合并到一个(!)页面(即覆盖)。 删除 --filename 时,生成的文档将是一个具有预期两页的 PostScript。
最佳答案
发生异常的原因是 2 个文档之一不遵循 Adobe 文档结构约定 (DSC),如果您想使用 Document
append
方法,则必须遵守该约定.
请改用SafeAppenderModifier
。这里有一个例子:http://www.ghost4j.org/highlevelapisamples.html (将 PDF 文档附加到 PostScript 文档)
关于java - 连接两个 PostScript 期间的 Ghost4j 类强制转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144068/