手动编码 Postscript 时,Ghostscript 会产生未定义的错误

Posted

技术标签:

【中文标题】手动编码 Postscript 时,Ghostscript 会产生未定义的错误【英文标题】:When hand coding Postscript, Ghostscript produces an undefined error 【发布时间】:2021-03-05 07:43:53 【问题描述】:

我已经有 20 年没有手工编写 Postscript 了,所以我打开 Bluebook 并将一些示例输入到一个名为 test.ps 的文件中。这是一个这样的例子:

%!PS
/doACircle
 0 0 54 0 360 arc stroke  def
/doAnEllipse
 1 .75 scale
doACircle
stroke  def
300 500 translate doACircle
4 0 −72 translate
doAnEllipse repeat
showpage

我在 Debian Linux 系统上使用 Ghostscript 和 Imagemagick。两者都适用于其他事情。当我运行这样的命令时:

convert test.ps test.png

我得到一个错误和一个转储:

Error: /undefined in �
Operand stack:
   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1992   1   3   %oparray_pop   1991   1   3   %oparray_pop   1979   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   3   --nostringval--   %repeat_continue   --nostringval--
Dictionary stack:
   --dict:727/1123(ro)(G)--   --dict:0/20(G)--   --dict:78/200(L)--
Current allocation mode is local
Current file position is 167
GPL Ghostscript 9.27: Unrecoverable error, exit code 1
Error: /undefined in �
Operand stack:
   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1992   1   3   %oparray_pop   1991   1   3   %oparray_pop   1979   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   3   --nostringval--   %repeat_continue   --nostringval--
Dictionary stack:
   --dict:727/1123(ro)(G)--   --dict:0/20(G)--   --dict:78/200(L)--
Current allocation mode is local
Current file position is 167
GPL Ghostscript 9.27: Unrecoverable error, exit code 1
convert-im6.q16: no images defined `test.png' @ error/convert.c/ConvertImageCommand/3258.

我知道我忘记了一些基本的东西——也许是与边界框相关的东西?

【问题讨论】:

【参考方案1】:

这是节目流中的一个奇怪的字符。我的猜测是 您使用的是 Macintosh 并且它是出于某种原因您的键盘处理程序正在用一些 表面上 更合适的破折号字符替换连字符。这会创建一个格式错误的负数,该负数会被解析为一个名称,然后......瞧...... dict 堆栈中没有定义这样的名称。

错误消息中可以帮助解决类似问题的一些线索是:

/undefined 错误是字典查找失败的结果。这可能发生在loadknownget 或在程序流中自动查找可执行文件名称时。 操作数堆栈转储显示单个 0,因此它必须发生在堆栈上只有一个 0 的地方。 表明 GS 遇到了一个不知道如何处理的角色。

【讨论】:

天啊。现在我觉得自己像个傻瓜。我正在从 Bluebook 的 PDF 版本中复制文本,其中连字符是印刷破折号。更换它们解决了问题。非常感谢。

以上是关于手动编码 Postscript 时,Ghostscript 会产生未定义的错误的主要内容,如果未能解决你的问题,请参考以下文章

手工编写基本的 PostScript 脚本

从 PostScript 中提取位图

无损压缩从 PostScript 生成的 PDF

将 EPS 图像插入 PostScript 文档

Tkinter Canvas Postscript 未捕获屏幕框架外的 Window 元素

Windows 8,打印到 PostScript 打印机到文件