100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 如何用python写程序设置当前打印机为默认打印机_从Python打印到标准打印机?

如何用python写程序设置当前打印机为默认打印机_从Python打印到标准打印机?

时间:2021-08-03 08:51:07

相关推荐

如何用python写程序设置当前打印机为默认打印机_从Python打印到标准打印机?

Is there a reasonably standard and cross platform way to print text (or even PS/PDF) to the system defined printer?

Assuming CPython here, not something clever like using Jython and the Java printing API.

解决方案

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.

You need to detect the OS your program is running on, then:

For Linux -

import subprocess

lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)

lpr.stdin.write(your_data_here)

More resources:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。