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

查看:433
本文介绍了使用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.

感谢您的帮助, 皮特

推荐答案

我最终使用了 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 \\server\printer "test.pdf"

来自python:

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天全站免登陆