This project turns a Raspberry Pi (2 Zero W) into a fully automated print server for shipping labels. It monitors a network folder that runs on the pi itself, automatically detects common German shipping carriers (DHL, Hermes, etc.) by filename, crops the PDFs to the correct size, and prints them on the Zebra GK420d (you can change it to any pritner you want).
-
Open the Network Folder:
- Windows:
\\<IP-OF-YOUR-PI>\LabelPrinter - Mac:
smb://<IP-OF-YOUR-PI>/LabelPrinter
- Windows:
-
Drop a PDF:
- Copy your label PDF into the
inputfolder.
- Copy your label PDF into the
-
Magic:
- The original file is immediately backed up to the
originalfolder. - The PDF is analyzed and cropped/rotated based on the filename.
- The printer outputs the label (4x6 inch).
- The processed file is moved to the
processedfolder.
- The original file is immediately backed up to the
The Samba share LabelPrinter contains three subfolders:
| Folder | Description |
|---|---|
input |
Drop files here. The watchdog monitors this folder for new PDFs. |
processed |
Contains the cropped/final PDFs after successful printing. |
original |
Contains the unmodified A4 originals as a backup. |
The script checks the filename to determine how to process the label:
| Type / Keyword | Action | Details |
|---|---|---|
DHL "DHL-Paketmarke" |
Crop | Removes typical A4 margins, keeps only the label area. |
Hermes "Hermes", "Paketschein_" |
Crop + Rotate | Cuts off the bottom half of the A4 page and rotates the label by 90° so it fits the 4x6 portrait format. |
Return Label "Rücksende-Etikett" |
Crop | Fallback for older Hermes return labels (bottom crop). |
Stamp "Briefmarken" |
Crop + Scale | Isolates the stamp (e.g., Internetmarke) and scales it up. |
| Amazon / Other | Direct Copy | No modification, printed via fit-to-page. |
Note: All print jobs are sent to CUPS with the
-o fit-to-pageoption to ensure they fill the 4x6 inch label.
- Python Script:
/home/admin/print_watchdog.py - Label Directory:
/home/admin/labels/ - System Service:
/etc/systemd/system/labelprinter.service
Check Status (Is the service running?):
sudo systemctl status labelprinter.servicesudo systemctl restart labelprinter.serviceView Logs (Debugging):
# Live logs (Exit with CTRL+C)
journalctl -u labelprinter.service -fEdit Script:
nano /home/admin/print_watchdog.pyIf you need to set up the system from scratch: Install Dependencies:
sudo apt install cups python3-pip
pip install watchdog pypdf --break-system-packages- Web Interface: https://:631
- Driver: Zebra ZPL Label Printer
- Name: Zebra_GK420d
- Media Size: 4x6 inch (or 100x150mm)
- Config file: /etc/samba/smb.conf
- Create share [LabelPrinter] pointing to /home/admin/labels (guest ok = yes).
- Create /etc/systemd/system/labelprinter.service.
- Enable it: sudo systemctl enable labelprinter.service.