Label Printing
Product labels with price and barcode, or address labels - on standard A4 label sheets, single labels from a thermal roll, or 4 x 6 inch courier shipping labels. Each label is drawn at an exact position in millimetres.
How it works
- A layout is a grid in millimetres: label width/height, top-left offset and gaps (
LabelPdfService.Layout). - PDF coordinates start at the bottom-left, so row r sits at
y = pageHeight - top - (r+1) x labelHeight. - Text goes into a box with
ColumnText(wraps and clips); barcodes are PNG images placed withsetAbsolutePosition. - Print label sheets at 100% / Actual size - "Fit to page" shrinks everything and the labels no longer line up.
float x = mm(layout.left + col * (layout.labelW + layout.gapX));
float y = mm(layout.pageH - layout.top - (row + 1) * layout.labelH - row * layout.gapY);
Rectangle box = new Rectangle(x, y, x + mm(layout.labelW), y + mm(layout.labelH));
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(box.getLeft(), box.getBottom(), box.getRight(), box.getTop());
ct.addElement(new Paragraph(product.getName(), Fonts.bold(8)));
ct.go();
Files: service/LabelPdfService.java.