【问题标题】:Ghostscript command line with postscript带有 postscript 的 Ghostscript 命令行
【发布时间】:2021-07-22 17:25:00
【问题描述】:

使用内联 postscript 语法时出现以下命令错误。可能是语法错误,但可以得到它有什么问题!

命令

"C:\Program Files\gs\gs9.54.0\bin\gswin64c.exe" -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -dNoCancel -dPDFFitPage -c mark "NoCancel true QueryUser 3 OutputFile (%printer%Microsoft Print to PDF) UserSettings <<DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice" -dNORANGEPAGESIZE -f "D:\95c46c9f-0007-415d-99b6-c9ee561821ab.pdf"

例外

GPL Ghostscript 9.54.0 (2021-03-30)
Copyright (C) 2021 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Error: /undefined in QueryUser
Operand stack:
   --nostringval--   true   true
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:740/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.54.0: Unrecoverable error, exit code 1

【问题讨论】:

  • 仅用于测试目的,使用 Microsoft Print to PDF。实际上,它应该在实际打印机上静默打印。上面的命令正在使用 c#,但我想使用 gs cli 进行检查。

标签: ghostscript


【解决方案1】:

这里是命令行,没有试图隐藏输出的所有包袱。

"C:\Program Files\gs\gs9.53.3\bin\gswin64c.exe" -sDEVICE=mswinpr2 -o "%printer%My Print to PDF" -dPrinted -dFitPage -dNORANGEPAGESIZE -f "C:\MyData\sample.pdf"

打印在没有提示的情况下无声运行,因为这就是我设置“我的打印为 PDF”而不是“MS 打印为 PDF”的方式,后者会喊出文件名。要让 GS 静音,请参见下文。

这意味着除了移动/重命名 output.pdf 之外,我不需要跳过扭曲

我正在显示打印假脱机,但这通常只是任务栏上的一个图标。我可以使控制台最小化,为了使 GSwin64C 静音,我需要添加 -q 和 -dNoCancel,但要注意你必须查看打印图标或添加“打印完成”语句。 注意:- 对于批处理文件,%% 需要加倍。

GSwin64C ^
-q ^
-sDEVICE=mswinpr2 ^
-dNoCancel ^
-o "%%printer%%My Print to PDF" ^
.... other switches

但我不打扰,因为我更喜欢在发生打印机错误时看到它们。

在我看来,这个练习毫无意义,它只是一个概念证明,因为输出文件远不如 input.pdf。是的,我可以降低分辨率或通过 GhostScript 驱动结果以进行压缩。

但是为什么因为它是一个非常好的 137 KB 可搜索文本 input.pdf 并且被降级为一个显着劣质的 113,021 KB 非文本 PDF。使用其他 CLI PDF 处理程序有几十种更简单的方法可以让结果差 825 倍(或更好)。然而,图像质量很好,正如我们对 GS 所期望的那样。

将文本 PDF 转换为图像 PDF 的更有效方法是

echo Method Two "Ghostscript Convert to PDF"

"C:\Path....\gs9.54.0\bin\gswin64c.exe" ^
-q ^
-sDEVICE=pdfimage32 ^
-o C:\MyData\output.pdf ^
-dPDFSETTINGS=/screen ^
-f "C:\MyData\input.pdf"

质量应该更好(我没有减少我本来可以做的位深度)因此文件大小对于 3,938 KB 的单声道来说非常大,但对于更多颜色来说它是 30% 的大小。 ?

[稍后编辑] 您评论了如何更改假脱机程序名称,实际上我认为它的临时名称没有问题,绰号是“Ghostscript 输出”或“Ghostscript 文档”。你可以称它为“任何其他名字的玫瑰”。但是我怀疑您的目标原因是最终文档中显示的“标题”标签。为此,您在命令行上使用 PDF 标记,这是一种非常脆弱的工作方式。

你的构造

-c mark "NoCancel true QueryUser 3 OutputFile (%printer%Microsoft Print to PDF) UserSettings <<DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice" -dNORANGEPAGESIZE -f "D:\95c46c9f-0007-415d-99b6-c9ee561821ab.pdf"

我在批处理文件中的尝试将类似于

-c "mark /OutputFile (%%printer%%Microsoft Print to PDF) /UserSettings <</DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice " -f "D:\95c46c9f-0007-415d-99b6-c9ee561821ab.pdf"

注意我包含了关键的 PS 除法=/ 并且需要在批处理文件中使用 %% 并且在 -c "...." 和 -f 之间没有任何内容

所以在这里我们在假脱机中看到“测试”

并“测试”将其放在 DragOnDrop.cmd 中

@echo off
"C:\Program Files\gs\gs9.54.0\bin\gswin64c.exe" -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -dNoCancel -dPDFFitPage -dNORANGEPAGESIZE ^
-c "mark /OutputFile (%%printer%%Microsoft Print to PDF) /UserSettings <</DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice " ^
-f %1

【讨论】:

  • 在这种情况下如何更改打印机假脱机中的文档名称?
猜你喜欢
  • 2017-04-12
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 2022-08-23
  • 1970-01-01
  • 2011-05-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多