我试图将两个PostScript文件连接到一个带有ghost4j 0.5.0的文件中,如下所示:
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");在这个简化的过程中,我得到了上面“追加”行的以下异常消息:
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合并为一个(!)页(即覆盖)。当删除--文件名时,生成的文档将是一个PostScript,并按预期分两页。
发布于 2013-12-30 20:49:55
出现此异常是因为两个文档中有一个不遵循(DSC),如果您想使用Document append方法,这是强制性的。
使用SafeAppenderModifier代替。这里有一个例子:http://www.ghost4j.org/highlevelapisamples.html (将一个PDF文档附加到PostScript文档中)
发布于 2013-11-22 12:45:45
我认为文档或XMLGraphics库中有问题,因为它似乎不能解析其中的一部分。
在这里,您可以在ghost4j中看到我认为它失败的代码(链接):
DSCParser parser = new DSCParser(bais);
Object tP = parser.nextDSCComment(DSCConstants.PAGES);
while (tP instanceof DSCAtend)
tP = parser.nextDSCComment(DSCConstants.PAGES);
DSCCommentPages pages = (DSCCommentPages) tP;在这里,您可以看到为什么XMLGraphics可以为sesponsable (链接)服务:
private DSCComment parseDSCComment(String name, String value) {
DSCComment parsed = DSCCommentFactory.createDSCCommentFor(name);
if (parsed != null) {
try {
parsed.parseValue(value);
return parsed;
} catch (Exception e) {
//ignore and fall back to unparsed DSC comment
}
}
UnparsedDSCComment unparsed = new UnparsedDSCComment(name);
unparsed.parseValue(value);
return unparsed;
}parsed.parseValue(value)似乎抛出了一个异常,它隐藏在catch中,并返回了ghost4j没想到的未解析版本。
https://stackoverflow.com/questions/20144068
复制相似问题