从Python打印到标准打印机? [英] Print to standard printer from Python?
问题描述
是否存在合理的标准和跨平台方式来将文本(甚至PS / PDF)打印到系统定义的打印机?
Is there a reasonably standard and cross platform way to print text (or even PS/PDF) to the system defined printer?
假设 CPython 在这里,并不是像使用Jython和 Java打印API 。
Assuming CPython here, not something clever like using Jython and the Java printing API.
推荐答案
不幸的是,不是在所有平台上使用Python进行打印的标准方法。因此,您需要编写自己的包装函数以进行打印。
Unfortunately, there is no standard way to print using Python on all platforms. So you'll need to write your own wrapper function to print.
您需要检测程序正在运行的操作系统,然后:
对于Linux-
import subprocess
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.stdin.write(your_data_here)
对于Windows: http://timgolden.me.uk/python/win32_how_do_i/print.html
For Windows: http://timgolden.me.uk/python/win32_how_do_i/print.html
更多资源:
使用python的win32print模块打印PDF文档吗?
如何使用Python打印到操作系统的默认打印机3(跨平台)?
这篇关于从Python打印到标准打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!