python-printer-command-line


Namepython-printer-command-line JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/rrakso/PythonPcl
SummaryNone
upload_time2024-06-09 02:13:06
maintainer"Oskar Jaskólski"
docs_urlNone
author"Dominique Meurisse"
requires_python>=3.6
licenseNone
keywords thermal printer labels zebra zpl pcl
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Hi, I'm currently reworking this README file for better presentation.

# Python PCL / ZPL

![Python PCL / ZPL logo](res/logo/PythonPcl-480px.png)

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](https://shop.mchobby.be).

![Zebra Label Printer](res/images/zebra-GK420T.png)

## 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](res/images/hp-pcl.png)

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_

- [/test/test-printer/zebra/demo-README.txt](test/test-printer/zebra/demo-README.txt)
- [/test/test-printer/zebra/demo.zpl](test/test-printer/zebra/demo.zpl)
- [/test/test-printer/zebra/demo-zebra-raw-queue-cups.pdf](test/test-printer/zebra/demo-zebra-raw-queue-cups.pdf)

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](http://domeu.blogspot.com/2020/01/imprimante-zebra-usb-en-reseau-avec.html)" (french)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rrakso/PythonPcl",
    "name": "python-printer-command-line",
    "maintainer": "\"Oskar Jask\u00f3lski\"",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "\"oskarrro90@gmail.com\"",
    "keywords": "thermal printer, labels, zebra, ZPL, PCL",
    "author": "\"Dominique Meurisse\"",
    "author_email": "\"info@mchobby.be\"",
    "download_url": "https://files.pythonhosted.org/packages/0f/ac/62fa18f3692becbc8c0e6df2fb8efc3115d34af4245a7b9c8ac034d665c2/python_printer_command_line-1.0.1.tar.gz",
    "platform": null,
    "description": "Hi, I'm currently reworking this README file for better presentation.\n\n# Python PCL / ZPL\n\n![Python PCL / ZPL logo](res/logo/PythonPcl-480px.png)\n\nPython PCL / ZPL allows you to control directly Zebra Printer & HP Printer with ZPL and HP PCL languages from Python script.\n\n## What is ZPL?\n\nZPL 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](https://shop.mchobby.be).\n\n![Zebra Label Printer](res/images/zebra-GK420T.png)\n\n## What is PCL?\n\nPCL 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\".\n\n![HP Printer](res/images/hp-pcl.png)\n\nThe advantage of PCL approach is to support advanced printer feature on:\n\n1. Archaic development plateform (eg: Clipper, Habour Projet)\n2. Operating Systems having few ressources (Raspberry Pi, MicroControleur, PyBoard)\n3. 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.\n\nThe 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!\n\n# Aim of this project\n\nThe aim of this projet is to provide a starting point to print directly on PCL 'like' printers from Python scripts.\n\nThe goals are:\n\n- Doing it with efficiency,\n- Using few ressources (work on small system, old computer, possibly Raspberry-Pi),\n- Supporting several communication layers\n- serial/usb printer,\n- CUPS raw / Windows Raw\n- IP printers.\n\nThe projet will target:\n\n- A4 Page printing with a networked HP 3015.\n- Adhesive label/tag printing with Zebra\n- Ticket printing with Epson (they support HP Pcl)\n\n# Which are the PCL printers on the market ?\n\nThe most known printers are certainly the HP LaserJet.\nA 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.\n\nZebra 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`\nWe 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.\n\nEpson should also support similar feature but I will examine this point later (will Epson TM80 been a good choice?)\n\nBrother 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.\n\n# Network Printer, USB/Serial printer, Managed printer\n\nPlease browse the content of `test` sub-folder, it contains many examples + image\ncapture to get started with the code.\n\n## Network Printer\n\nTo print on a Network printer, you must use a `PrinterSocketAdapter` class which\nabstract communication over the an Ethernet Network.\n\nWhen creating such `PrinterSocketAdapter` adapter, you must give a tuple of `('Printer_IP_adress', Printer_port )` .\n\nOn HP Network printer, the usual printer port is 9100.\n\nExample: medium = `PrinterSocketAdapter( ('192.168.1.206', 9100) )`\n\n## USB Printer\n\nYou can also connect an USB printer. In most of the time, such printer will be taken in charge by CUPS on Linux machine.\n\nSuch USB printer uses the `PrinterSerialAdapter` class with abstract communication over a serial device.\n\nTo identify such file:\n\n1. Open a terminal.\n2. Connect the printer.\n3. type de command `dmesg | tail` this will show debug message were it will be possible to identify the device path.\n\nexample of log:\n\n```\n[102813.855412] usb 2-1.3: new full-speed USB device number 16 using ehci-pci\n[102813.949086] usb 2-1.3: New USB device found, idVendor=0a5f, idProduct=00a3\n[102813.949094] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3\n[102813.949100] usb 2-1.3: Product: ZTC LP 2824 Plus\n[102813.949105] usb 2-1.3: Manufacturer: Zebra Technologies\n[102813.949110] usb 2-1.3: SerialNumber: 36J141701319\n[102814.002703] usblp 2-1.3:1.0: usblp0: USB Bidirectional printer dev 16 if 0 alt 0 proto 2 vid 0x0A5F pid 0x00A3\n[102814.002745] usbcore: registered new interface driver usblp\n```\n\nNote: The printer can also be found by exploring `/dev/usb/` .\n\nIn the present usecase, the printer has been located at `/dev/usb/lp0` .\n\nWhen creating such `PrinterSerialAdapter` adapter, you must give 2 parameters: the Printer_device and Printer_Baud .\n\nExample: `medium = PrinterSerialAdapter( '/dev/usb/lp0', 9600 )`\n\n_Warning !_ On some operating systems, the printer will be managed by a print spooler (like CUPS).\nIn such case, the USB device cannot be open directly (because owned by CUPS).\nIn such case, you will have to use a `PrinterCupsAdapter` instead of `PrinterSerialAdapter` !\nIf you wire a Zebra on Linux Mint, CUPS will take the printer in charge!\n\n## Managed USB Printer\n\nDepending on the Operating System, Linux Version and printer, the USB printer may be taken\nin charge by a print spooler. The printer is managed (usually by CUPS).\n\nIn such case, the python Script cannot access the USB port with a `PrinterSerialAdapter` class!\nInstead, you will have to install the printer as a RAW DEVICE (see ressource) and use\nthe class `PrinterCupsAdapter` to send the PCL command through CUPS.\n\nexample of log:\n\n```\n[102813.855412] usb 2-1.3: new full-speed USB device number 16 using ehci-pci\n[102813.949086] usb 2-1.3: New USB device found, idVendor=0a5f, idProduct=00a3\n[102813.949094] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3\n[102813.949100] usb 2-1.3: Product: ZTC LP 2824 Plus\n[102813.949105] usb 2-1.3: Manufacturer: Zebra Technologies\n[102813.949110] usb 2-1.3: SerialNumber: 36J141701319\n[102814.002703] usblp 2-1.3:1.0: usblp0: USB Bidirectional printer dev 16 if 0 alt 0 proto 2 vid 0x0A5F pid 0x00A3\n[102814.002745] usbcore: registered new interface driver usblp\n```\n\nIf you pay attention to the log here upper (already showned for USB devices), the _usbcore_ did register a new interface driver\nnamed `usblp` (so `lp` is the software to use for print files).\n\nWe known then that the printer will be taken in charge by CUPS.\n\nSuch managed USB printer uses the `PrinterCupsAdapter` class with abstract communication over a CUPS printer.\n\nWhen creating such `PrinterCupsAdapter` adapter, you must give the CUPS queue name to access the printer .\n\nExample: `medium = PrinterCupsAdapter( printer_queue_name = 'zebra-raw' )`\n\n### Installing a RAW printer with CUPS\n\nIf you want to send command (like ZPL to a Zebra printer) it is very important to install such printer as a _RAW printer_.\n\nThe needed steps and testing have been described in the following files\n\n- /test/test-printer/zebra/demo*.* files\n\n_We strongly recommand to read the following files_\n\n- [/test/test-printer/zebra/demo-README.txt](test/test-printer/zebra/demo-README.txt)\n- [/test/test-printer/zebra/demo.zpl](test/test-printer/zebra/demo.zpl)\n- [/test/test-printer/zebra/demo-zebra-raw-queue-cups.pdf](test/test-printer/zebra/demo-zebra-raw-queue-cups.pdf)\n\nThe last file `demo-zebra-raw-queue-cups.pdf` is in french but you should be able\nto easily identify the various screen of `Raw Queue` installation for a the Zebra USB printer.\n\n### Use a Raspberry-Pi as CUPS server to share USB Zebra printer\n\nThis is described in our article \"[Imprimante Zebra USB en r\u00e9seau avec CUPS sur Raspberry-Pi](http://domeu.blogspot.com/2020/01/imprimante-zebra-usb-en-reseau-avec.html)\" (french)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/rrakso/PythonPcl"
    },
    "split_keywords": [
        "thermal printer",
        " labels",
        " zebra",
        " zpl",
        " pcl"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f3618eec4a7403103cfcdeeb7cc59d7c4d0d1a2cab428ddc7b55a0b3471fd0fa",
                "md5": "899b38032a68803c2cdae8d711f774d5",
                "sha256": "402cc1a3222b6be670085a0717b9a27d79b9936609e2df42cd3ffa7284e061ea"
            },
            "downloads": -1,
            "filename": "python_printer_command_line-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "899b38032a68803c2cdae8d711f774d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 28728,
            "upload_time": "2024-06-09T02:13:04",
            "upload_time_iso_8601": "2024-06-09T02:13:04.460006Z",
            "url": "https://files.pythonhosted.org/packages/f3/61/8eec4a7403103cfcdeeb7cc59d7c4d0d1a2cab428ddc7b55a0b3471fd0fa/python_printer_command_line-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fac62fa18f3692becbc8c0e6df2fb8efc3115d34af4245a7b9c8ac034d665c2",
                "md5": "39cca35d2c959b4164c6956dd9382f3b",
                "sha256": "79ca7fb6bf04a3f257af9a966658b73ccd029ff8754146300ff9ba74be827d96"
            },
            "downloads": -1,
            "filename": "python_printer_command_line-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "39cca35d2c959b4164c6956dd9382f3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 26850,
            "upload_time": "2024-06-09T02:13:06",
            "upload_time_iso_8601": "2024-06-09T02:13:06.631197Z",
            "url": "https://files.pythonhosted.org/packages/0f/ac/62fa18f3692becbc8c0e6df2fb8efc3115d34af4245a7b9c8ac034d665c2/python_printer_command_line-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-09 02:13:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rrakso",
    "github_project": "PythonPcl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-printer-command-line"
}
        
Elapsed time: 2.09063s