elliothatch / zine-machine

print formatted text passages on a receipt printer at the press of a button
GNU General Public License v2.0
2 stars 0 forks source link

I take it this was made for 80mm (3") thermal printers and not 58mm (2") ones? #1

Open gloriouslyawkwardlife opened 3 months ago

gloriouslyawkwardlife commented 3 months ago

Works fine, except it appears to be solely for 3"-wide (80mm) printers?

elliothatch commented 3 months ago

Hello! The project was developed using a generic "LMP201" printer we happened to purchase, which is an 80mm printer. However, the code should work with any printer that uses the ESC/POS protocol, including 58mm printers, as long as it is supported by the underlying protocol library we used (python-escpos).

I hadn't really anticipated outside interest in this project, so I never finished adding all the configuration flags, meaning that the only way to configure the project for your specific printer is to fork the repo and modify the code yourself. If you are really interested in the project, I would be happy to take some time to forward the necessary configuration options to the command-line interface and the python module so you don't have to fork it yourself, although I can't guarantee how soon I can get around to that.

If you want to fork the repo yourself instead, follow the development instructions. Then there are 2 places you'll need to make a small tweak to the code.

Printer profile

The python-escpos library has a concept of "printer profiles", which describe the capabilities of the printer, such as supported commands (codepage support, font choices, image printing, qr code printing, etc.) and physical dimensions of the printer (e.g. used for rendering images). If your printer isn't a no-name Chinese brand like mine, there is probably already an existing available profile for your printer.

You can import the correct profile and pass it to the Zine Machine in __main__.py#L30.

If you don't find your printer in the list, you can create your own profile by modifying our custom LMP201 profile in profile.py. This profile just copies the "Default" profile and changes the printer dimensions (used for image and QR code printing), and removes some problematic codepages (our LMP201 did not fully implement some codepages, and also has some custom codepages that use the same identifiers as standardized codepages, which caused issues with the python-escpos auto-encoder, resulting in lot of text being printed out as garbage, until those codepages were disabled).

Column width

You will also need to set the number of characters your printer prints in a single line of text, for the text wrapping to work correctly. The default value is 48.

Change zinemachine.py#L63 to the following code, replacing 'width' with the number of columns for your printer.:

zine.initMarkup(textwrapOptions={
        'width': 48,
        'expand_tabs': True,
        'tabsize': 4
    });

Other options

There are some other hardcoded options that can also be modified by passing configurations to zine.printZine() in zinemachine.py. These control the default styles (we default all text to bold to increase readability) and printing options for images and QR codes.

Anyway, let me know if these instructions work for you. If you have any issues, let me know and I will try to prioritize adding the configuration options properly. The main reason I haven't added them already is because I don't have the printer on-hand right at the moment and don't want to push untested code.