Writing your own CUPS printer driver in 100 lines of Python (2018)

146 todsacerdoti 18 5/25/2025, 3:52:48 PM behind.pretix.eu ↗

Comments (18)

behnamoh · 8h ago
https://gimp-print.sourceforge.io/ which uses CUPS helped me resurrect an old Canon printer for which the company refused to provide updated drivers on macOS.

I was about to throw it in the recycling/trash, but I just couldn't accept that a perfectly fine hardware was crippled because the software was not updated to work on the latest macOS versions. Perplexity pointed me to Gutenprint and it worked wonderfully! The only thing that doesn't work is the scanner functionality.

exhilaration · 4h ago
I bought VueScan in 2014 specifically for a Canon scanner, looks like it's still around: https://www.hamrick.com/
asveikau · 8h ago
Many years ago I remember Windows support vanished on a bunch of printers at the 32 to 64 bit transition. That was around the time I learned how printing on Linux and BSD worked, to save a printer or two.
LargoLasskhyfv · 6h ago
Did you try http://sane-project.org for the scanner part? They have support for some Canons, maybe you're lucky?
ValdikSS · 5h ago
>Unfortunately, CUPS sends us grayscale values and our printer only supports pixels that are either fully black or white. Since we do not want to drop grayscale values compeltely, we want to apply Dither.

CUPS can send black-and-white 1 bit data, dithered. It's just a matter of proper option in a PPD file. It could also handle rotation by itself.

Other than that, pretty good and accurate article! I bet you can write the driver (filter) even in <50 lines of Python code :P

userbinator · 7h ago
However, the license of the BOCA driver forbids using their driver to control printers of other vendors.

Since this is a printer, I interpret those the same way as "you're not allowed to use third-party ink": I don't care.

ValdikSS · 5h ago
Oh!

Take a look at EPSON printer driver, which prohibits you from:

1. Sharing the printer you own with anyone else unless they agree to the license of the driver (incl. business setup)

2. Sharing the printer over the internet unconditionally, because this allows to use the driver for people who did not agree to the license

3. Incorporating the driver in any "revenue generating product or service"

https://download.ebz.epson.net/la/linux/inkjet_for_linux.htm...

1. Grant of License.

[…] provided that the Software is used (i) only in a single location (e.g., a home or office or place of business), or in the case of a mobile device, on a Device owned or otherwise controlled by you, and (ii) only in connection with Epson Hardware owned by you. You may allow other users of the Epson Hardware connected to your network to use the Software, provided that you shall ensure that such users use the Software only in accordance with this Agreement. You agree to be responsible for and indemnify Epson for liabilities incurred as a consequence of use by such users.

3. Other Rights and Limitations.

[…] Further, you agree not to place the Software onto or into a shared environment accessible via a public network such as the Internet or otherwise accessible by others outside the single location referred to in Section 1 above.

You may not rent, lease, distribute, lend the Software to third parties or incorporate the Software into a revenue generating product or service.

ale42 · 5h ago
Personally, I don't either. But if you're a business, you probably need to care even if you don't want to.
userbinator · 4h ago
Enforceability of EULAs has always been a rather open-ended question.
Havoc · 1h ago
Ideally don't buy a thermal printer at all. The paper usually contains BPA. You found one that says BPA free? Yep they switched to BPS. Also toxic and harmful to reproductive health.

If you absolutely must - use a European supplier - both are banned there for thermal paper.

zrobotics · 52m ago
I was about to write an incredulous comment accusing you of licking receipts, but I thought I'd look into it first. It does appear that just handling thermal paper can expose you to BPA [0].

Such a shame, thermal printers are the only printing device I don't suspect of being a plot by Satan to tempt us into wrathful thinking. Thermal printers are insanely reliable, I've worked IT for several businesses with shipping departments and thermal label printers are less troublesome than even keyboards, I struggle to think of a class of equipment that generated less issues. I guess I should have suspected there was something devious about them, they are printers after all and all other printers I've had to support have always just been constant sources of annoying issues.

[0] https://www.pca.state.mn.us/business-with-us/bpa-and-bps-in-...

dqv · 19m ago
That article has a good alternative though: ascorbic acid. I think the last time I looked into this I had a hard time finding thermal labels that used ascorbic acid, but they at least have receipt paper. I do still have concerns that even the ascorbic acid paper still has something bad in it absent any documentation going over the full ingredient list.
devmor · 5m ago
I had the same incredulity when BPA alarms started going off, thinking it was another Prop 65 warning type thing. Finding out that it is literally absorbed through the skin sent shivers down my spine. That stuff is scary.
roywashere · 9h ago
Pretix is a very interesting piece of open source software for selling event tickets. It’s nice to see them venturing out to writing printer drivers for ticket printers! All the best for them.
saltcured · 8h ago
This takes me waaaaaaaay back to when I did my first bit of practical low-level programming. I wrote a little C program that translated PNM bitmaps into the wire format for my dusty 24-pin Epson dot matrix printer. I don't remember the details, but I used it with some plugin system involving Ghostview to print postscript documents from my first Linux system in the early 90s.
dale_huevo · 4h ago
This is great.

Until now I thought CUPS drivers had to be written in C in order to link against its internal APIs.

Most inexpensive Chinese thermal printers ship with blatantly GPL violating drivers and they are precompiled binaries. Which means half the time they won't work in your situation, assuming you trust their probable malware in the first place.

whycome · 7h ago
Is there an LLM specifically for this use case scenario?
a-ungurianu · 6h ago
I’m not clear what you’re asking with this question.

Do you mean a LLM to write printer drivers? For that I think any of the coding LLMs should be able to help

Or do you mean using an LLM to do the raster -> FGL format translation? While I’m sure it might be possible, feels like an awful waste of resources, and when it comes to printers, you kinda want the guarantee that what comes out is the same that comes in.