使用 Python 将打印作业发送到 USB 打印机 [英] Send a print job to USB printer using Python

查看:129
本文介绍了使用 Python 将打印作业发送到 USB 打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从 PDF、PRN 或 PS 文件开始.如何使用 Python 将其发送到 USB 打印机?我应该从哪个模块开始?

I can start with a PDF, PRN, or PS file. How do I send it to a USB printer using Python? What module should I get started with?

推荐答案

听起来您使用的是 Windows,所以让我们从这个开始 - 如果您使用的是 Linux,答案会有所不同.

It sounds like you're using Windows, so let's start with that - the answer changes if you're using Linux.

在 Windows 中有两种打印方式.第一种最常见的方法是通过 Windows GDI 界面发送单独的绘图命令.为此,您必须将页面上的每个单独元素放置在适当的位置(文本字符串、图像和形状),同时选择适当的颜色和字体.如果你自己生成数据很容易,如果你必须解析你正在阅读的文件,那就更难了.

There are two ways to print within Windows. The first most common way is to send individual drawing commands through the Windows GDI interface. To do this you must place every individual element on the page in its proper location (text strings, images and shapes) while selecting the proper colors and fonts. Easy if you're generating the data yourself, much harder if you have to parse a file that you're reading.

另一种选择是以原始"模式发送到打印机,其中打印机驱动程序基本上被绕过.为此,打印机必须在本机上理解您提供给它的字节流.有一些打印机本身就可以理解 Postscript,但我不确定 PDF,而且 PRN 不是标准格式.

The other option is to send to the printer in a "raw" mode, where the printer driver essentially gets bypassed. For this to work the printer must natively understand the stream of bytes that you feed to it. There are some printers that understand Postscript natively, but I'm not sure about PDF, and PRN isn't a standard format.

我自己从来没有通过 Python 进行过原始打印,但这里有一个链接到一小段示例代码(以及预期问题的想法):http://bytes.com/topic/python/answers/512143-printing-raw-postscript-data-windows

I've never done raw printing through Python myself, but here's a link to a short snippet of sample code (and an idea of the problems to expect): http://bytes.com/topic/python/answers/512143-printing-raw-postscript-data-windows

这篇关于使用 Python 将打印作业发送到 USB 打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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