我正在使用ghost4j jar将PostScript转换为PDF。当内容中存在某些高位ASCII字符时,转换将失败。奇怪的是,并非所有的高位ASCII都会导致此问题。来自Ghostscript的错误信息对我没有帮助。
产生问题的示例代码为:
private void convertPSToPDF()
{
try
{
File ps = new File( "c:\\temp\\gsinput.ps" );
PSDocument document = new PSDocument();
document.load( ps );
File pdf = new File( "c:\\temp\\gsoutput.pdf" );
FileOutputStream stream = new FileOutputStream( pdf );
try
{
PDFConverter converter = new PDFConverter();
converter.setPDFSettings( PDFConverter.OPTION_PDFSETTINGS_PRINTER );
converter.convert( document, stream );
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
stream.close();
}
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
}
}
log4j的输出如下:
0 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - Error: /undefined in y0m
1 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - Operand stack:
1 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - (3) 375.4 36.3
1 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - Execution stack:
2 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 2045 1 3 %oparray_pop 2044 1 3 %oparray_pop 2025 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
2 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - Dictionary stack:
2 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - --dict:961/1684(ro)(G)-- --dict:0/20(G)-- --dict:282/300(L)--
2 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - Current allocation mode is local
2 [AWT-EventQueue-0] INFO org.ghost4j.Ghostscript - Last OS error: No such file or directory
2 [AWT-EventQueue-0] ERROR org.ghost4j.Ghostscript - GPL Ghostscript 9.26: Unrecoverable error, exit code 1
这似乎暗示了PostScript的这一行:
(3)375.4 36.3 y0 bnum
但是,我看不到有什么问题,如果我在文件的其他位置进行了一些小的更改,该行也可以正常运行。我注意到该问题仅发生在其中带有'í'或'á'字符的源文件中……但是'ú'看起来很好。
基于此,似乎会产生问题的PostScript片段只是试图编写一些字符串文字:
328.9 -25.8 M /str{ 18.0 F4 [(An S)/uacute(is)/iacute(n Ban)]arrayshow}def
strw w 0.5 mul neg 0 RM str
0.0 -36.8 M 10.0 F4 (Other)show
0 -36.80 T
0 -6.00 T
如果我更改PostScript以普通的“ i”替换“í”字符(/ iacute),问题将消失。该代码将起作用:
328.9 -25.8 M /str{ 18.0 F4 [(An S)/uacute(isin Ban)]arrayshow}def
strw w 0.5 mul neg 0 RM str
0.0 -36.8 M 10.0 F4 (Other)show
0 -36.80 T
0 -6.00 T
在log4j输出之后,我得到一个IOException。似乎这在代码内部只是差的错误处理,因为此时我们不应该删除文件。调用堆栈的顶部是:
java.io.IOException: Temporary file C:\Users\Tad\AppData\Local\Temp\ghost4j\452f1844-372a-4300-b570-86ec650fe4b6@17580 cannot be deleted
at org.ghost4j.util.DiskStore.removeFile(DiskStore.java:133)
没有特殊字体;只是时代罗马。我正在使用Ghostscript DLL的v9.26。
有人对我如何解决这个问题有任何建议吗?如果有任何避免的方法,我真的不想在最终输出中替换那些外来字符。