Home Contents | # gcx:barcode | Graphics | Core4 Lua Commands

## SYNOPSIS

1. width, height = gcx:barcode(type, x, y, module_width, module_height, text [, param])
2. width, height = gcx:barcodesize(type, x, y, module_width, module_height, text [, param])
3. width, height = gfx.barcodesize(type, x, y, module_width, module_height, text [, param])

## DESCRIPTION

The first form draws a barcode onto the graphics context. The barcode can then be printed by using one of the conversion functions like gcx:encode() or gcx:save().

The second and third forms allows calculating the size of a barcode without actually drawing it. (The third form is slightly more efficient and does not require a graphics context, but previous SDK versions had only the second form available.)

type indicates the barcode type to be drawn. The barcodes can be grouped into linear and 2D codes. Click on one of the barcodes listed below to get more information on that code.

### Linear barcodes

- EAN
- Code93
- Code128
- Code25m
- Code25i

### 2D barcodes

- PDF417
- QR-Code

## RETURN VALUE

On success, returns the width and height of the resulting barcode in pixels. If the barcode cannot be drawn due to invalid parameters, returns nil, nil.

## EXAMPLE

Assume we have a connection to a THSP ticket printer open and the handle stored in the variable printer. This code will generate a QR-Code and store it inside the printer's image buffer.

Real application code might want to keep the bcbuf buffer around in some long term variable, to avoid having it created and destroyed each time a barcode is printed.

function generate_barcode(printer, bctext) local bcbuf = gfx.new(256,256,1) bcbuf:color(0x000000) bcbuf:bgcolor(0xFFFFFF) local bcw, bch = bcbuf:barcode("QR", 0, 0, 3, 3, bctext, { version=3, ecc="H" }) bcbuf:saveat(0, 0, bcw, bch, printer, "FPM") bcbuf:close() end