用python的win32print模块打印PDF文档? [英] Print PDF document with python's win32print module?

查看:29
本文介绍了用python的win32print模块打印PDF文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 win32print 模块打印 PDF 文档.显然这个模块只能接受 PCL 或原始文本.那是对的吗?

I'm trying to print a PDF document with the win32print module. Apparently this module can only accept PCL or raw text. Is that correct?

如果是,是否有可将 PDF 文档转换为 PCL 的模块?

If so, is there a module available to convert a PDF document into PCL?

我考虑使用 ShellExecute;但是,这不是一个选项,因为它只允许打印到默认打印机.我需要通过各种网络的服务器上的各种打印机进行打印.

I contemplated using ShellExecute; however, this is not an option since it only allows printing to the default printer. I need to print to a variety of printers on servers across various networks.

感谢您的帮助,皮特

推荐答案

我最终使用了 Ghostscript 来完成这个任务.有一个依赖于 Ghostscript 的命令行工具 gsprint.

I ended up using Ghostscript to accomplish this task. There is a command line tool that relies on Ghostscript called gsprint.

您甚至不需要安装 Acrobat 即可以这种方式打印 PDF,这非常好.

You don't even need Acrobat installed to print PDFs in this fashion which is quite nice.

这是一个例子:

在命令行上:

gsprint -printer \serverprinter "test.pdf"

来自蟒蛇:

win32api.ShellExecute(0, 'open', 'gsprint.exe', '-printer "\\' + self.server + '\' + self.printer_name + '" ' + file, '.', 0)

请注意,我已在这些示例中添加到我的 PATH 变量中,因此在调用可执行文件时不必包含整个路径.

Note that I've added to my PATH variable in these examples, so I don't have to include the entire path when calling the executable.

然而,有一个缺点.该代码是根据 GPL 许可的,因此它在商业软件中不是很有用.

There is one downside, however. The code is licensed under the GPL, so it's no very useful in commercial software.

希望这对某人有所帮助,皮特

Hope this helps someone, Pete

这篇关于用python的win32print模块打印PDF文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆