My brother is setting up a store on Flipkart. Most of the early work is unglamorous: listing products, packing orders and printing shipping labels. I assumed printing would be the easy part. It wasn’t.
The Label Problem
For every order, Flipkart Seller Hub gives you a PDF to print. It is an A4 page with the shipping label at the top and the tax invoice below it, separated by a dashed line. That works if you have a regular printer and a pair of scissors.
The plan was to print labels on a cheap thermal printer instead. These print on 4×6 inch label rolls and never need ink. But they want a 4×6 label, not an A4 page.
So I tried to cut the label out of the PDF. Adobe Reader can crop a PDF, but cropping is a paid feature. Next came the Snipping Tool and MS Paint: snip the label, paste it, print. The label came out the right size, but the low resolution messed up the barcode.
A shipping label with a barcode that won’t scan is of no use.
Why the Barcode Breaks
A thermal printer has no shades of grey. Each dot on the print head either heats the paper black or leaves it white. Most cheap ones print 203 dots per inch, which is 8 dots per millimetre.
A snip is captured at screen resolution, usually far fewer pixels than the printer needs. Stretch it up to 203 dpi and the sharp edge of every bar turns into a soft grey ramp. The printer then has to decide, pixel by pixel, whether that grey becomes black or white.
Some bars come out fatter, some thinner, and the edges get ragged. Text survives this because your eyes are forgiving. A barcode doesn’t: it stores data in the widths of its bars and gaps, so when the widths drift, the scanner reads garbage or nothing at all.
Enter Label Cropper
So I did what I usually do with an annoying problem: I built a small web app for it. You drop in the Seller Hub PDF and it:
- Finds the dashed line between the label and the invoice, and crops out the label. If it guesses wrong, drag a box on the page to pick the area yourself.
- Renders the label at your printer’s real resolution, 203 or 300 dpi.
- Converts it to pure black and white, so the printer has no grey pixels to guess about.
- Gives you a PDF that is exactly 4×6 inches (or 3×5, or the label’s exact size), plus a PNG if you want one.
PDFs with many pages work too. Each page becomes a label, and you can download the whole batch as one PDF.
One thing to remember while printing: choose Actual size (100%), not Fit to page. The PDF is already the right size, and any extra scaling brings the blur back.
The Engineering Bits
The trick is to never touch a screenshot. Inside the PDF, the label is vector data: the text, lines and barcode bars are shapes, not pixels. pdf.js, the PDF renderer that ships with Firefox, can draw those shapes at any resolution.
So the app renders just the label area, directly at the printer’s resolution. At 203 dpi, a 4×6 label is 812 × 1218 pixels, one pixel for every dot on the print head, so the printer has nothing left to scale. Each pixel is then forced to black or white with a brightness threshold, a call the printer driver would otherwise make for you, and not always well.
Finding the dashed line was the fun part. The app scans the page row by row, looking for a row whose dark pixels cover at least a quarter of the width, stretch across most of the page, and flip between dark and light more than 30 times. A solid border fails the last test, and a line of text usually fails the first.
If there is no dashed line, say the PDF is already just a label, it crops to whatever is printed on the page. The final PDF is built with jsPDF, with the page set to the exact label size.
Nothing Leaves the Browser
A shipping label carries the customer’s name and address. I didn’t want that going to a server, mine or anyone else’s. So there is no server: everything happens in your browser.
The app is a single HTML file plus pdf.js and jsPDF, hosted as static files on S3 behind Cloudflare. The page also sends a Content Security Policy, which tells the browser to block it from sending data to any other site. Even if the app had a bug, it couldn’t ship your PDF off to another site.
Try It
The app is live at labelcutter.spendsort.com. It is free, there is no sign-up, and it is built around Flipkart Seller Hub’s label format.
I’d love feedback. If a label doesn’t crop right, or you want support for another marketplace’s labels, leave a comment and I’ll take a look. And if it saves you a trip to MS Paint, I’d love to hear that too.
Leave a Reply