The blog article My Magic Zebra Printer - Why Software Rules the World has a demo of Magic Zebra Printer in action
A simple script to automatically determine the paper length for an image or PDF file (based on the last page) and print it on a label printer.
My Zebra label printer has a roll of continuous paper and a cutter so that it can print any page size by simply cutting off the paper at the appropriate length.
My problem is that I use it to print all sorts of shipping labels or other small info pages that have different page sizes. Previously I used to create many different custom page sizes to accomodate different print jobs. With this script everything happens automatically:
- Scale down the page to 4 inch wide and rotate landscape to portrait to maximize print size
- Determine the page length required for the print job
- Determine the printer (looking for
*zebra*
) to use - Should work on Mac, Linux & Windows
- Includes PDF Service, Service and Application for MacOS. Application can be put into Dock as drag-n-drop target.
-
Install the prerequisites with
brew install imagemagick potrace
or (Mac)sudo apt install imagemagick potrace
(Debian/Ubuntu) -
Make sure to have Python 3.6 or later installed.
-
Checkout this Git repo into a directory of your choice, I use
/Users/schlomo/src/magic-zebra-printer
on MacOS and you will have to adjust that later. -
Create a Python 3 Virtual Environment named
venv
viapython3 -m venv venv
. -
Activate it with
source venv/bin/activate
and install the Python module dependencies withpip install -r requirements.txt
.
-
Copy the content of macos to your
$HOME
directory. -
Edit to each of the following files and adjust the path to your Git checkout:
~/Library/PDF Services/Zebra Printer.workflow/Contents/document.wflow
~/Library/Services/Zebra Printer.workflow/Contents/document.wflow
~/Applications/Zebra Printer.app/Contents/document.wflow
In each file, search for
/Users/schlomo/src/magic-zebra-printer
and replace it with the path where you checked out the Git repo. -
Open the "Privacy & Security" settings and add the
Zebra Printer
Application from your$HOME/Applications
to the list of applications with Full Disk Access. This will enable drag and drop for the application without a security confirmation.
Now you should be able to use the Zebra Printer as a PDF Print Action, as a Service in other apps and Finder and as a standalone application which can serve as a drag-and-drop target.
-
Edit the path in
linux/magic-zebra-printer.desktop
to match the Git checkout -
(If you want to print images too) Disable the ImageMagic policy that prevents PDF writing, see https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion for details, typically this should do the trick:
sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml`
-
Install the desktop file:
desktop-file-install --rebuild-mime-info-cache --dir=$HOME/.local/share/applications linux/magic-zebra-printer.desktop
-
Add the following alias to your shell, e.g. to
$HOME/.bash_aliases
, of course adjusting for the path of the Git checkout:function mzp { ( source /home/schlomo/src/magic-zebra-printer/venv/bin/activate ; exec python /home/schlomo/src/magic-zebra-printer/magic-zebra-printer.py "$@" ) }
Now you can use Magic Zebra Printer to open PDF and image files via the "Open with other application" context menu in the file manager. You can also use it as a command line tool by calling mzp
For Windows I'm happy to accept your contribution with a suitable integration.
Simple open a PDF file with the Magic Zebra Printer application (you can use drag and drop onto the launcher for this) or use the Zebra Printer service or PDF Service with it.
On the command line pass the PDF file to print as the first argument. Optionally pass -noprint
as second argument to suppress printing. It will leave the intermediate file for you to examine (next to the original file).
To set the printer (instead of using the first printer to contain "zebra" in its name), set the MAGIC_ZEBRA_PRINTER
environment variable with the name of the desired printer.
- Not much error handling, no tests
- No proper installation, but runs from git checkout
- I have no clue about MacOS internals and "just got it to work". So I'll be happy to get any feedback.
- I couldn't find a way to create a convenient drag-drop target on Linux, feedback & ideas are welcome.