Send a print job to USB printer using Python

17,883

Solution 1

As far as I know, these are the two package available:

  1. pkipplib
  2. win32print

Solution 2

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

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.

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.

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

Share:
17,883
Kit
Author by

Kit

Updated on June 07, 2022

Comments

  • Kit
    Kit almost 2 years

    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?

  • Bugs
    Bugs about 7 years
    A code dump, whist it may be technically correct, doesn't necessarily help the OP or future visitors. I would pad out the answer by explaining the code, even comments within the code are helpful.