Overview
The Problem
- Some vendors embed the label as a separate image inside the PDF
- Some draw the label with vector boxes and text
- Some put the label beside instructions or a return authorization page
- Some include QR codes that are not shipping labels at all
- Some labels are sideways, scaled oddly, or surrounded by whitespace
- Some documents have medical, invoice, or receipt-shaped pages that look label-like if you only score geometry
How It Works
- Look for embedded PDF images with a 4x6-ish aspect ratio
- Look for vector rectangles that resemble generated label boxes
- Render the page and find dense label-like regions
- Decode barcodes and identify carrier tracking numbers when possible
- Ask Gemini through LiteLLM only when the deterministic result is missing barcode-like shipping evidence or falls below the confidence threshold
Confidence Gates
- High-confidence label with shipping evidence: show preview and allow normal print
- Ambiguous label: show preview, but require an explicit "print anyway" style confirmation
- No convincing label: reject the upload instead of manufacturing a fake 4x6 output
Printing
Web UI
- Drag a PDF, PNG, JPG, or HEIC anywhere onto the page
- See the extracted 4x6 preview before printing
- Download the generated PDF or PNG
- Review alternate candidate crops when a document is ambiguous
- Batch several ready labels and print them together
- Reopen recent jobs from history
- Copy or open carrier tracking links when barcode decoding finds them
What Made It Worth Custom Building
- A full-page return PDF where the label is embedded sideways
- A disclosure page that looks label-shaped but is not a label
- A QR-only return code that should not be treated as shipping evidence
- A printer that validates one media name but accepts another job ticket shape
- A barcode decoder that sees routing data before the actual tracking number
- A batch print UI that needs to report partial failures honestly
Tech Stack
- Python 3.11+ with FastAPI for the upload, preview, job history, and print API
- PyMuPDF, Pillow, and NumPy for PDF rendering, image processing, and 4x6 normalization
- zxing-cpp for barcode decoding and carrier/tracking extraction
- LiteLLM + Gemini 3.5 Flash for bounded vision fallback on ambiguous documents
- ipptool / IPP for direct Rollo X1040 printing and job-state confirmation
- Vanilla HTML/CSS/JS for the no-build-step web UI
- Kubernetes, Envoy Gateway, Cloudflare Access, and GHCR for my homelab deployment