CatPrint.swift
A coworker recently started a project that uses a thermal printer to print some information for a top secret purpose and I was immediately inspired to play around with one myself. Unfortunately the thermal printer that they were using was more than £150 and designed for commercial environments and after some searching I ordered one of these ‘cat’ printers from Aliexpress — which was £15 including shipping, 7 rolls of paper and 3 rolls of stickers.
Once I received the printer I hurriedly started trying out lots of iOS thermal printer SDKs — but unfortunately they were mostly all designed for the more expensive commercial printers and refused to connect. I inspected the app bundle that the printer came with, which was an obfuscated react native application, and managed to find where connecting to the printer was handled but I did not relish the idea of spending hours trying to unpick my way through the obfuscation. I went back to searching the internet and eventually found that, though the printer model gave me zero results, I got plenty of results for “cat printer” — happy days.
I used this Python project by rbaron, and confirmed that it could print successfully. I then set about to trying out the printer commands in that repo in my own Swift project and it worked! I built a small Swift SDK that I could use for my own project that prints a CGImage
— additionally handling some image processing to prepare the image for the printer. You can use a SwiftUI
ImageRenderer
to very easily create a CGImage
with arbitrary content for printing, but how you create your image is entirely up to the user of the library.
I released CatPrint.swift
on GitHub. If you are interested in printing from iOS/macOS/iPadOS please take a look and try it out.
michael | benzoate.net | 2023-12-27 |