|
| 1 | +# EAN |
| 2 | + |
| 3 | +EAN comes in a variety of forms, most commonly used is EAN-13 (GTIN-13) that is used on world wide to marking the identity of products. |
| 4 | + |
| 5 | +`qrx` supports the formats EAN-13, EAN-8 and UPC as well as the barcode addons EAN-5 and EAN-2. |
| 6 | + |
| 7 | +## Supported modes |
| 8 | + |
| 9 | +```ts |
| 10 | +import { barcode } from '@stacksjs/qrx' |
| 11 | + |
| 12 | +barcode('#barcode', '5901234123457', { format: 'EAN13' }) |
| 13 | +barcode('#barcode', '123456789999', { format: 'UPC' }) |
| 14 | +barcode('#barcode', '96385074', { format: 'EAN8' }) |
| 15 | +barcode('#barcode', '54495', { format: 'EAN5' }) |
| 16 | +barcode('#barcode', '53', { format: 'EAN2' }) |
| 17 | +``` |
| 18 | + |
| 19 | +## Addon EAN-5 / EAN-2 |
| 20 | + |
| 21 | +EAN-5 and EAN-2 is addon barcodes an is always used combined with EAN-13 or EAN-8. |
| 22 | +The advanced barcode syntax can be used to add these addons to the barcodes. |
| 23 | + |
| 24 | +```ts |
| 25 | +import { barcode } from '@stacksjs/qrx' |
| 26 | + |
| 27 | +barcode('#barcode') |
| 28 | + .EAN13('1234567890128') |
| 29 | + .blank(20) // An blank creates a space between the barcodes |
| 30 | + .EAN5('12345', { height: 85, textPosition: 'top', fontSize: 16 }) |
| 31 | + .render() |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +## `flat` options for EAN-13, EAN-8 and UPC |
| 37 | + |
| 38 | +EAN-13, EAN-8 and UPC barcodes is most often used with "guard bars". If you don't want these and instead a flat rendering you can specify the `flat` option and skip the guard bars. |
| 39 | + |
| 40 | +```ts |
| 41 | +import { barcode } from '@stacksjs/qrx' |
| 42 | + |
| 43 | +barcode('#barcode', '1234567890128', { |
| 44 | + format: 'ean13', |
| 45 | + flat: true |
| 46 | +}) |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +## `lastChar` options for EAN-13 |
| 52 | + |
| 53 | +EAN-13 is sometimes printed with with a character after the barcode, most common is the `>` character. This is supported in barcode with the `lastChar` option. |
| 54 | + |
| 55 | +```ts |
| 56 | +import { barcode } from '@stacksjs/qrx' |
| 57 | + |
| 58 | +barcode('#barcode', '1234567890128', { |
| 59 | + format: 'ean13', |
| 60 | + lastChar: '>' |
| 61 | +}) |
| 62 | +``` |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +## OCR-B font |
| 67 | + |
| 68 | +When creating an EAN or UPC barcode it is standard to use the [OCR-B](https://en.wikipedia.org/wiki/OCR-B) font. Most variants of this font is not free. There are free versions but none that (we have found) that have the correct license to be able to include in the barcode repository. |
| 69 | + |
| 70 | +When using a custom font with barcode you can specify the font with [@font-face](https://developer.mozilla.org/en/docs/Web/CSS/@font-face) and then do the barcode call. Note that the font has to be loaded before the generation can be made correctly. |
| 71 | + |
| 72 | +```ts |
| 73 | +barcode('#canvasBarcode', '123456789012', { |
| 74 | + format: 'EAN13', |
| 75 | + font: 'OCRB', |
| 76 | + fontSize: 18, |
| 77 | + textMargin: 0 |
| 78 | +}) |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +## Check digits |
| 84 | + |
| 85 | +EAN-13, UPC and EAN-8 all have the last digit being a check digit to verify the content that is encoded. This digit is considered a part of the number and barcode will verify it before generating the barcode. |
| 86 | + |
| 87 | +If the last digit of these barcodes are not specified it will automatically be calculated and added. |
| 88 | + |
| 89 | +```ts |
| 90 | +barcode('#barcode', '96385074', { format: 'EAN8' }) |
| 91 | +// These two are generating identical barcodes |
| 92 | +barcode('#barcode', '9638507', { format: 'EAN8' }) |
| 93 | +``` |
0 commit comments