如何修复 Python Ghostscript 程序打印空白 pdf 文件的问题?

问题描述 投票:0回答:1

我正在尝试将 pdf 文件从文件夹打印到硬质副本以供用户使用。 pdf 文件很好,简单的标签表(附有屏幕截图),程序运行良好,但如果我将 pdf 打印到文件,输出文件是空白 pdf,如果我将其打印到 OneNote,它会给我以下消息。我已经下载并使用了 32 版本的 gswin32 和 gsprint,但为了好玩,我也尝试了 64 版本,但没有成功。任何和所有的帮助、建议、指导、指示将不胜感激:

import os
import win32print
import win32api

currentprinter = win32print.GetDefaultPrinter()
print(currentprinter)
gspath = "gswin32.exe"
gsp_path = "gsprint.exe"

for i in os.listdir(r"C:\guis\Temppdffolder"):
    print(i)
    path = r"C:\guis\Temppdffolderf"+"\%s"%(i)
    win32api.ShellExecute(0, 'open', gsp_path, '-ghostscript "'+gspath+'" -printer "'+currentprinter+'" "%s"'%(path), '.', 0)

python pdf printing ghostscript
1个回答
0
投票

GSprint 不是 Ghostscript 的一部分,它是一个非常古老的应用程序,与名为 GhostGum GSview 的衍生查看器一起使用,该查看器在过去很多个月里已被放弃。

为了安全地打印到现代打印机,您最好使用(目前版本 10.02.0)非商业 AGPL(或商业许可证)Ghostscript 或 GhostPCL GhostXPS 或总体 GhostPDL

对于 Windows,编程语法为 GS 或 gswin##c.exe(其中 ## 为 32 或 64)

例如

"c:\path to\gswin32c.exe"  [switches] [file1.ps file2.ps ...]

注意重点是 PS 作为预期输入,但 PDF 也处理得非常好。

Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF

许多用于编程文件输出的开关可以用 -oc:\path\out.pdf 或类似的图像替换。

要打印到设备,有两种方法,一种是直接到打印机,另一种是通过 MS 系统

-sDEVICE=mswinpr2

因此您尝试以编程方式使用 Ghostscript 是不正确的。所以你需要查看https://ghostscript.readthedocs.io/en/latest/Use.html

© www.soinside.com 2019 - 2024. All rights reserved.