以编程方式打印 PDF 文件 - 指定打印机 [英] Programmatically Print a PDF File - Specifying Printer
本文介绍了以编程方式打印 PDF 文件 - 指定打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 Python 脚本打印现有的 PDF 文件.
I have a requirement to print an existing PDF file from a Python script.
我需要能够在脚本中指定打印机.它在 Windows XP 上运行.
I need to be able to specify the printer in the script. It's running on Windows XP.
知道我能做什么吗?
这个方法 看起来可行,只是我不能指定打印机:
This method looks like it would work except that I cannot specify the printer:
win32api.ShellExecute (
0,
"print",
filename,
None,
".",
0
)
推荐答案
有一个文档不足的 printto
动词,它将打印机名称 作为参数(如果包含空格,则用引号括起来).
There's an underdocumented printto
verb which takes the printer name as a parameter (enclosed in quotes if it contains spaces).
import tempfile
import win32api
import win32print
filename = tempfile.mktemp (".txt")
open (filename, "w").write ("This is a test")
win32api.ShellExecute (
0,
"printto",
filename,
'"%s"' % win32print.GetDefaultPrinter (),
".",
0
)
这篇关于以编程方式打印 PDF 文件 - 指定打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文