Metadata-Version: 2.5
Name: rasterprynt2
Version: 2.0.0
Summary: Print raster graphics on Brother P-Touch label printers (PT-P950NW, PT-9800PCN)
Project-URL: Source, https://heptapod.backend.at/tryton/rasterprynt2/
Author-email: Philipp Hagemeister <philipp.hagemeister@boxine.de>
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Printing
Requires-Python: >=3.10
Requires-Dist: pillow
Description-Content-Type: text/markdown

# rasterprynt2

rasterprynt2 is a Python library and program to print raster graphics on various label printers. As of writing, the following printers are supported:

- Brother PT P950NW
- Brother PT 9800PCN

This uses an undocumented reverse-engineered protocol, similar to the one in use by [brother_ql](https://github.com/pklaus/brother_ql/tree/master/brother_ql).

## Supported tape sizes and printable widths

The number of dots in the print area (the "stripe size") depends on the printer
model and tape width, and images must be scaled to the printable height for the
selected printer/tape combination. The vertical resolution is 360 dpi on both
supported printers.

| Tape width | Printable width | PT-P950NW (dots) | PT-9800PCN (dots) |
|-----------:|----------------:|-----------------:|------------------:|
| 6 mm       | 4.5 mm          | 64               | 64                |
| 9 mm       | 7.5 mm          | 106              | 106               |
| 12 mm      | 10.6 mm         | 150              | 150               |
| 18 mm      | 16.5 mm         | 234              | 234               |
| 24 mm      | 22.6 mm         | 320              | 320               |
| 36 mm      | 27.1 / 32.0 mm  | 454              | 384               |

Supported tape sizes (usable with `--tape-size`): **6mm, 9mm, 12mm, 18mm, 24mm,
36mm**. All of these are continuous (non die-cut) tape; the media format
registry also supports die-cut label formats with a fixed label length —
adding a new media format is a matter of adding one entry to the `MEDIA`
registry in `rasterprynt2/__init__.py`.

These values were verified against the official Brother documentation; the
full table with byte widths is available in
[docs/STRIPE_SIZES.md](docs/STRIPE_SIZES.md).

## Installation

Install from the [Heptapod repository](https://heptapod.backend.at/tryton/rasterprynt2/):

    $ pip install hg+https://heptapod.backend.at/tryton/rasterprynt2/@default#egg=rasterprynt2

To install the dependencies for a command-line installation from a checkout, type

    $ pip install -r requirements.txt

## Command Line Usage

All functionality is available as a command-line program, like this:

   $ python -m rasterprynt2 192.168.1.123 img1.png img2.jpg img1.png --top-margin 10

## Library Usage

The main method is `rasterprynt2.prynt`, which takes a list of images. Cuts will be inserted in between the images.

    import rasterprynt2

    import PIL.Image

    # Enter the IP address of your printer below
    printer_ip = '192.168.1.123'

    img1 = PIL.Image.open('example1.png')
    img2 = PIL.Image.open('example2.png')
    data = rasterprynt2.prynt([img1, img2, img1], printer_ip)

## Additional utilities

`plotimg.py` (repository root) provides a way to do the reverse transformation:
it parses the binary data stream that was sent to a printer and renders it back
into a portable bitmap (Netpbm P1). This is useful to inspect exactly what
would be printed without touching real tape.

CLI usage:

    $ ./plotimg.py [-f {auto,pcap,bin}] [-w FILE.bin] INPUT_FILE OUTPUT_FILE

- `INPUT_FILE` is either a raw binary instruction stream (`.bin`) or a pcap
  capture of the TCP traffic to the printer.
- With `-f auto` (the default), the format is detected from the file content;
  use `-f pcap` or `-f bin` to override.
- With `-w FILE.bin`, the raw (pcap-stripped) binary data is written to disk
  before it is decoded.
- `OUTPUT_FILE` receives the reconstructed image in Netpbm (P1) format.
- For pcap input, the optional dependency [scapy](https://scapy.net/) is
  required (`pip install scapy`). TCP payloads sent to the printer's port
  9100 are reassembled and plotted.

Example:

    $ ./plotimg.py capture.pcap out.pbm
