windows下如何用python控制打印机打印

来源:互联网 发布:windows正版验证原理 编辑:程序博客网 时间:2024/06/07 02:45

参考网址
首先下载python需要的库

pip install pypiwin32

简单例子

import tempfileimport win32apiimport win32printfilename = tempfile.mktemp (".txt")open (filename, "w").write ("This is a test")win32api.ShellExecute (  0,  "print",  filename,  #  # If this is None, the default printer will  # be used anyway.  #  '/d:"%s"' % win32print.GetDefaultPrinter (),  ".",  0)

但实际上这只是打印自己制定的字符串, 并且打印出来会显示txt的文件名。所以我更倾向于使用windows的cmd指令打印指定文件。

原创粉丝点击