Skip to main content

No project description provided

Project description

Hi, I'm currently reworking this README file for better presentation.

Python PCL / ZPL

Python PCL / ZPL logo

Python PCL / ZPL allows you to control directly Zebra Printer & HP Printer with ZPL and HP PCL languages from Python script.

What is ZPL?

ZPL is a "tuned version" of PCL for Zebra label printer. Initially started for HP printers, this project evolved to support Zebra ZPL format. ZPL is now used every day with Zebra LP2824 Plus & Zebra GK420t at MC Hobby.

Zebra Label Printer

What is PCL?

PCL stand for "Printer Command Line". Meaning that some printer behavior (font, font size, bold, graphics, barcode) can be controled by including some special command inside the text stream being printer. Those special commands are usually introduced by the escape character (ASCII #27). As a result, such printer command are also commonly named "Escape Sequence".

HP Printer

The advantage of PCL approach is to support advanced printer feature on:

  1. Archaic development plateform (eg: Clipper, Habour Projet)
  2. Operating Systems having few ressources (Raspberry Pi, MicroControleur, PyBoard)
  3. Exactly controling the whole printing process (no drivers stack, no printer spoeler). You can send bytes direcly to the printer? So you are pretty sure to be able to print something.

The inconvenient of such approach is that you have to take care yourself of the printing process, page layout, etc. No software in between (like cups or other document generator) means that you have to do it yourself!

Aim of this project

The aim of this projet is to provide a starting point to print directly on PCL 'like' printers from Python scripts.

The goals are:

  • Doing it with efficiency,
  • Using few ressources (work on small system, old computer, possibly Raspberry-Pi),
  • Supporting several communication layers
  • serial/usb printer,
  • CUPS raw / Windows Raw
  • IP printers.

The projet will target:

  • A4 Page printing with a networked HP 3015.
  • Adhesive label/tag printing with Zebra
  • Ticket printing with Epson (they support HP Pcl)

Which are the PCL printers on the market ?

The most known printers are certainly the HP LaserJet. A wide range of HP Printer support for HP/PCL. We are currently using PCL it to print invoice from an 20 years clipper software still maintained nowadays (compiled with "Harbour project"). We are using a Networked HP3015 and this is working Pretty fine.

Zebra is also proposing PCL support (they call it ZPL for Zebra Programming Langage). The general principles stays identical. Zebra did also released many other PCL langages. I did place sereval links into the /res/ressources.txt We bought an affordable Zebra LP 2824 Plus and we have tamed the beast by implementing ZPL in the library. Since, we are also using the library with Zebra GK420T.

Epson should also support similar feature but I will examine this point later (will Epson TM80 been a good choice?)

Brother has an affordable Brother ticket printer (QL-570) is not well supported on Linux machine. Controling that printer directly seems to be a nightmare (even with technical documentation). So this library will not manage the QL-570.

Network Printer, USB/Serial printer, Managed printer

Please browse the content of test sub-folder, it contains many examples + image capture to get started with the code.

Network Printer

To print on a Network printer, you must use a PrinterSocketAdapter class which abstract communication over the an Ethernet Network.

When creating such PrinterSocketAdapter adapter, you must give a tuple of ('Printer_IP_adress', Printer_port ) .

On HP Network printer, the usual printer port is 9100.

Example: medium = PrinterSocketAdapter( ('192.168.1.206', 9100) )

USB Printer

You can also connect an USB printer. In most of the time, such printer will be taken in charge by CUPS on Linux machine.

Such USB printer uses the PrinterSerialAdapter class with abstract communication over a serial device.

To identify such file:

  1. Open a terminal.
  2. Connect the printer.
  3. type de command dmesg | tail this will show debug message were it will be possible to identify the device path.

example of log:

[102813.855412] usb 2-1.3: new full-speed USB device number 16 using ehci-pci
[102813.949086] usb 2-1.3: New USB device found, idVendor=0a5f, idProduct=00a3
[102813.949094] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[102813.949100] usb 2-1.3: Product: ZTC LP 2824 Plus
[102813.949105] usb 2-1.3: Manufacturer: Zebra Technologies
[102813.949110] usb 2-1.3: SerialNumber: 36J141701319
[102814.002703] usblp 2-1.3:1.0: usblp0: USB Bidirectional printer dev 16 if 0 alt 0 proto 2 vid 0x0A5F pid 0x00A3
[102814.002745] usbcore: registered new interface driver usblp

Note: The printer can also be found by exploring /dev/usb/ .

In the present usecase, the printer has been located at /dev/usb/lp0 .

When creating such PrinterSerialAdapter adapter, you must give 2 parameters: the Printer_device and Printer_Baud .

Example: medium = PrinterSerialAdapter( '/dev/usb/lp0', 9600 )

Warning ! On some operating systems, the printer will be managed by a print spooler (like CUPS). In such case, the USB device cannot be open directly (because owned by CUPS). In such case, you will have to use a PrinterCupsAdapter instead of PrinterSerialAdapter ! If you wire a Zebra on Linux Mint, CUPS will take the printer in charge!

Managed USB Printer

Depending on the Operating System, Linux Version and printer, the USB printer may be taken in charge by a print spooler. The printer is managed (usually by CUPS).

In such case, the python Script cannot access the USB port with a PrinterSerialAdapter class! Instead, you will have to install the printer as a RAW DEVICE (see ressource) and use the class PrinterCupsAdapter to send the PCL command through CUPS.

example of log:

[102813.855412] usb 2-1.3: new full-speed USB device number 16 using ehci-pci
[102813.949086] usb 2-1.3: New USB device found, idVendor=0a5f, idProduct=00a3
[102813.949094] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[102813.949100] usb 2-1.3: Product: ZTC LP 2824 Plus
[102813.949105] usb 2-1.3: Manufacturer: Zebra Technologies
[102813.949110] usb 2-1.3: SerialNumber: 36J141701319
[102814.002703] usblp 2-1.3:1.0: usblp0: USB Bidirectional printer dev 16 if 0 alt 0 proto 2 vid 0x0A5F pid 0x00A3
[102814.002745] usbcore: registered new interface driver usblp

If you pay attention to the log here upper (already showned for USB devices), the usbcore did register a new interface driver named usblp (so lp is the software to use for print files).

We known then that the printer will be taken in charge by CUPS.

Such managed USB printer uses the PrinterCupsAdapter class with abstract communication over a CUPS printer.

When creating such PrinterCupsAdapter adapter, you must give the CUPS queue name to access the printer .

Example: medium = PrinterCupsAdapter( printer_queue_name = 'zebra-raw' )

Installing a RAW printer with CUPS

If you want to send command (like ZPL to a Zebra printer) it is very important to install such printer as a RAW printer.

The needed steps and testing have been described in the following files

  • /test/test-printer/zebra/demo*.* files

We strongly recommand to read the following files

The last file demo-zebra-raw-queue-cups.pdf is in french but you should be able to easily identify the various screen of Raw Queue installation for a the Zebra USB printer.

Use a Raspberry-Pi as CUPS server to share USB Zebra printer

This is described in our article "Imprimante Zebra USB en réseau avec CUPS sur Raspberry-Pi" (french)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_printer_command_line-1.0.2.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_printer_command_line-1.0.2-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file python_printer_command_line-1.0.2.tar.gz.

File metadata

File hashes

Hashes for python_printer_command_line-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2920f4d108ac073ab3fed7f293f93247a70d4a05250e0cd3670a70b1d193d782
MD5 3ea31cbb4319fccad88b8b66713e3cd7
BLAKE2b-256 940906217cb493bb0ea413c4b571b4cd67c018417cf2634a44f956349a67d7d7

See more details on using hashes here.

File details

Details for the file python_printer_command_line-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python_printer_command_line-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 11650f4e7726e8dd1d7998df1d4b0e8982ce286e342834b1219e9e7effe0c1dd
MD5 fc9d560001d674c1a5f13f496dbbf966
BLAKE2b-256 1d5592ac8c1af228fc72b8cbc80558983738782cc267480de6d6ca02ca79a3b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page