Thermal Label Printing Math: DPI, Dots per mm and Barcodes That Actually Scan
If you generate shipping or product labels from a web or mobile app, sooner or later a barcode prints fine on screen but refuses to scan.
Nine times out of ten the cause is simple arithmetic: your design was not snapped to the printer's dot grid.
Step 1: Convert DPI to dots per mm
Thermal printers burn whole dots. A 304 DPI head gives:
dots_per_mm = 304 / 25.4 ≈ 11.97 ≈ 12 dots/mm
A common 203 DPI head gives about 8 dots/mm. Everything you draw should be a whole number of dots.
Step 2: Know your printable width
The paper roll width is not your canvas. A 58 mm roll has margins, and the print head is narrower than the roll, so check the printable width in the spec sheet.
Then:
const dpi = 304;
const dotsPerMm = dpi / 25.4;
const printableMm = 48; // example value: confirm for your printer
const canvasWidthDots = Math.floor(printableMm * dotsPerMm); // 574
Render your label to a canvas exactly that many pixels wide and send it 1:1. Any scaling step will smear thin bars.
Step 3: Snap barcode modules to whole dots
A 1D barcode is built from "modules" (the narrowest bar). If the module is 2.5 dots wide, the printer rounds some bars up and some down and the ratios break.
function moduleDots(targetMm, dotsPerMm) {
return Math.max(2, Math.round(targetMm * dotsPerMm)); // never below 2 dots
}
const m = moduleDots(0.25, 304 / 25.4); // 3 dots = 0.25 mm per module
Then check the whole barcode still fits: for Code 128, width in modules depends on the data, so compute it before choosing the module size, and drop to a smaller module only if it still stays at 2+ dots.
Step 4: Practical checks
- Use direct thermal rolls of the right width; ordinary paper prints blank on a direct thermal printer.
- Print in pure black and white. Grey anti-aliasing turns into random dots.
- Test-scan a barcode every time you change roll type.
The example numbers here (304 DPI, 58 mm rolls) come from a real compact Bluetooth label printer; the thermal label printer spec page is a handy reference if you are working with similar hardware.
Comments
No comments yet. Start the discussion.