从 Python 打印到标准打印机? [英] Print to standard printer from Python?

查看:54
本文介绍了从 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屋!

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