My Magic Zebra Printer - Why Software Rules the World

Software rules the world, and everybody is its subject. But you can be a ruler, too - if you like I keep telling my family. Here is a little example where I try to rule my secondary printer by automating the tedious task of rotating and scaling content to print.

My Little Zebra Printer

My secondary printer (shown here on the shelf in my home office) is a little miracle device: It is a thermal transfer receipt printer, that prints on a roll of continuous paper that is 10cm (4in) wide. Specifically a Zebra GX420d. You can get such a used printers relatively cheap. This is exactly a printer like you know from your local supermarket. And it is a super useful tool to have at home, as many print jobs don't require a full A4 page and don't need to be printed on fancy bright white paper with ever-lasting toner.

Most common print jobs are shipping labels (no need to cut them to size), small shopping lists (fits in a pocket), little notes to stick into a book (e.g. reading order for a 15-book series) or even "internet tickets" (the code your kids get for another 45 mins of Internet access). My printer even has a cutter that can cut off the paper at the desired length after printing. So the page size (at least the length) can be flexible, and doesn't need to be fixed.

The nearly only problem with such a printer is using it: Adjusting the print size and format in any application is a multi-click process that is tedious. The print driver also only offers some default page sizes, which means that either my printout is cut off, split onto multiple pages or I get a lot of blank page - depending on how the page size has the wrong setting.

Python to the Rescue

To solve all these problems I wrote a little Python script called magic-zebra-printer.py (available as Open Source on my GitHub account), that automates all of the above. It

  • accepts PDF and image (any format) files
  • converts images to work well on a black/white printer with the help of mkbitmap from the potrace software package, like this sample image used in the mkbitmap documentation:
  • rotates the pages so that they are always printed in portrait 
  • scales the content so that the short edge of the content fits the full width of the paper (10cm).
  • determine the correct page length to minimize waste
  • works on MacOS, Linux (and probably Windows too)
  • provides an Application and PDF Service (MacOS) for quick access e.g. via drag and drop

The script is quite short (only about 250 lines) and works fairly well and I use it nearly every day to print something. It is not a big thing, but it afforded me the opportunity to learn a bit about PDF manipulation in Python via the great pypdf library.

And I got to learn - the hard way - how to turn a command line program into something you can use with the mouse on MacOS.

Demo

The following demo illustrates how I take a screenshot (using Shottr) of my GitHub page and drag this screenshot onto the Magic Zebra Printer application in my Dock, which prints it and shows me a success notification. That is how I most of the times use the printer, by simply selecting something on the screen and printing it via a single drag-and-drop movement. No settings to make, nothing to adjust.

The printout looks like this (scanned), you can clearly see how the screenshot has been optimized for B/W printing:


Software Rules the World...

... but you can still change your own surroundings and be a ruler in your own domain. I hope that this little story will encourage you to not just be a subject to the software that others wrote, but to go ahead and write something that will make your life easier, even if it is just saving you a few clicks. I promise that the feeling of accomplishment for creating your own tools is well worth the effort!

Comments

Like this content? You could send me something from my Amazon Wishlist. Need commercial support? Contact me for Consulting Services.

Popular posts from this blog

Overriding / Patching Linux System Serial Number

A Login Security Architecture Without Passwords

Fixing Chrome Color Printing on Linux with HP Color LaserJet M880