barcode

fun barcode(data: String, symbology: BarcodeSymbology = BarcodeSymbology.Code128, width: Dp? = null, height: Dp = Dp(50f), color: PdfColor = PdfColor.Black, background: PdfColor? = PdfColor.White)

Appends a 1D barcode encoding data with the chosen symbology.

  • BarcodeSymbology.Code128 (default): printable ASCII 32–126; digit runs compress automatically via code set C and the mandatory mod-103 checksum is appended for you.

  • BarcodeSymbology.Ean13: 12 digits (check digit computed) or 13 digits (check digit verified).

  • BarcodeSymbology.UpcA: 11 digits (check digit computed) or 12 digits (check digit verified); rendered as the equivalent EAN-13 symbol.

Readers expect a quiet zone of roughly ten modules on both sides — give the barcode some horizontal breathing room. The human-readable caption customary under retail barcodes is not drawn automatically; add a centred text(data) below when you need one.

Parameters

data

payload; invalid input for the symbology throws IllegalArgumentException.

symbology

which 1D encoding to use; defaults to Code 128.

width

rendered width; null uses the symbol's natural size of one PDF point per module.

height

bar height — taller bars are easier to scan.

color

bar colour.

background

fill behind the bars; null for transparent.