Design
Barcode
Add a :barcode tag to a temporary picture, and Carbone replaces it with a barcode or a QR code generated from your JSON data.
ENTERPRISE FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v3.4.6+
Overview
Compatible with PDF, ODT, ODS, ODP, ODG, PPTX, XLSX, DOCX, and HTML files
Carbone supports 107 barcodes.
There are two ways to insert a barcode:
- As a dynamic image: the recommended solution for generating industry-standard barcodes.
- As a font: the previous solution, which is not recommended, and only supports 4 barcodes.
Both solutions require the :barcode(type) tag in the template. Check the examples below for each method.
Get inspired by one of our real-life examples: Barcode Label, Ticket or E-Ticket
Barcodes as image
Generating a barcode as an image follows the same logic as dynamic pictures and involves three steps:
- Insert a temporary picture in your template. This will help Carbone determine where to insert the barcode.
- Write the Carbone tag (ex.
{d.value:barcode(type)}) followed by the barcode formatter in the alternative text, description, or title of the image. Refer to the dynamic pictures documentation for details. - Specify the
typeof barcode as the first argument of the:barcodeformatter. Check the list of supported barcodes. Finally, generate the document, and voilà!
Barcode options are available and can be passed to the :barcode formatter as additional arguments, such as :barcode(type, options1, options2, ...). See the list of barcode options for details.
Supported barcodes
| Barcode name | Type |
|---|---|
| EAN-5 (5 digit addon) | ean5 |
| EAN-2 (2 digit addon) | ean2 |
| EAN-13 | ean13 |
| EAN-8 | ean8 |
| UPC-A | upca |
| UPC-E | upce |
| ISBN | isbn |
| ISMN | ismn |
| ISSN | issn |
| Code 128 | code128 |
| GS1-128 | gs1-128 |
| GS1-14 | ean14 |
| SSCC-18 | sscc18 |
| Code 39 | code39 |
| Code 39 Extended | code39ext |
| Italian Pharmacode | code32 |
| Pharmazentralnummer (PZN) | pzn |
| Code 93 | code93 |
| Code 93 Extended | code93ext |
| Interleaved 2 of 5 (ITF) | interleaved2of5 |
| ITF-14 | itf14 |
| Deutsche Post Identcode | identcode |
| Deutsche Post Leitcode | leitcode |
| GS1 DataBar Omnidirectional | databaromni |
| GS1 DataBar Stacked | databarstacked |
| GS1 DataBar Stacked Omnidirectional | databarstackedomni |
| GS1 DataBar Truncated | databartruncated |
| GS1 DataBar Limited | databarlimited |
| GS1 DataBar Expanded | databarexpanded |
| GS1 DataBar Expanded Stacked | databarexpandedstacked |
| GS1 North American Coupon | gs1northamericancoupon |
| Pharmaceutical Binary Code | pharmacode |
| Two-track Pharmacode | pharmacode2 |
| Code 25 | code2of5 |
| Industrial 2 of 5 | industrial2of5 |
| IATA 2 of 5 | iata2of5 |
| Matrix 2 of 5 | matrix2of5 |
| COOP 2 of 5 | coop2of5 |
| Datalogic 2 of 5 | datalogic2of5 |
| Code 11 | code11 |
| BC412 | bc412 |
| Codabar | rationalizedCodabar |
| USPS Intelligent Mail | onecode |
| USPS POSTNET | postnet |
| USPS PLANET | planet |
| Royal Mail 4 State Customer Code | royalmail |
| AusPost 4 State Customer Code | auspost |
| Royal Dutch TPG Post KIX | kix |
| Japan Post 4 State Customer Code | japanpost |
| MSI Modified Plessey | msi |
| Plessey UK | plessey |
| Telepen | telepen |
| Telepen Numeric | telepennumeric |
| PosiCode | posicode |
| Codablock F | codablockf |
| Code 16K | code16k |
| Code 49 | code49 |
| Channel Code | channelcode |
| Flattermarken | flattermarken |
| Custom 1D symbology | raw |
| Custom 4 state symbology | daft |
| Miscellaneous symbols | symbol |
| PDF417 | pdf417 |
| Compact PDF417 | pdf417compact |
| MicroPDF417 | micropdf417 |
| Data Matrix | datamatrix |
| Data Matrix Rectangular | datamatrixrectangular |
| Data Matrix Rectangular Extension | datamatrixrectangularextension |
| Royal Mail Mailmark | mailmark |
| QR Code | qrcode |
| Swiss QR Code | swissqrcode |
| Micro QR Code | microqrcode |
| Rectangular Micro QR Code | rectangularmicroqrcode |
| MaxiCode | maxicode |
| Aztec Code | azteccode |
| Compact Aztec Code | azteccodecompact |
| Aztec Runes | aztecrune |
| Code One | codeone |
| Han Xin Code | hanxin |
| DotCode | dotcode |
| Ultracode | ultracode |
| GS1 Composite 2D Component | gs1-cc |
| EAN-13 Composite | ean13composite |
| EAN-8 Composite | ean8composite |
| UPC-A Composite | upcacomposite |
| UPC-E Composite | upcecomposite |
| GS1 DataBar Omnidirectional Composite | databaromnicomposite |
| GS1 DataBar Stacked Composite | databarstackedcomposite |
| GS1 DataBar Stacked Omnidirectional Composite | databarstackedomnicomposite |
| GS1 DataBar Truncated Composite | databartruncatedcomposite |
| GS1 DataBar Limited Composite | databarlimitedcomposite |
| GS1 DataBar Expanded Composite | databarexpandedcomposite |
| GS1 DataBar Expanded Stacked Composite | databarexpandedstackedcomposite |
| GS1-128 Composite | gs1-128composite |
| GS1 Data Matrix | gs1datamatrix |
| GS1 Data Matrix Rectangular | gs1datamatrixrectangular |
| GS1 QR Code | gs1qrcode |
| GS1 DotCode | gs1dotcode |
| HIBC Code 39 | hibccode39 |
| HIBC Code 128 | hibccode128 |
| HIBC Data Matrix | hibcdatamatrix |
| HIBC Data Matrix Rectangular | hibcdatamatrixrectangular |
| HIBC PDF417 | hibcpdf417 |
| HIBC MicroPDF417 | hibcmicropdf417 |
| HIBC QR Code | hibcqrcode |
| HIBC Codablock F | hibccodablockf |
| HIBC Aztec Code | hibcazteccode |
Barcodes options
Options must be passed as a second argument in any order, and must keep the format "optionName:value", such as: {d.number:barcode(qrcode, width:300, height:100, includetext:false, scale:1)}.
| Option name | Type | Description |
|---|---|---|
| svg | boolean | Generate SVG images (no pixels) Example: {d.number:barcode(qrcode, svg:true)} |
| width | integer | Width of the barcode in millimeters, maximum 1000 (a bigger value is ignored). Example: {d.number:barcode(qrcode, width:300)} Can be combined with :imageFit, e.g., {d.number:barcode(qrcode, width:300):imageFit(contain)} |
| height | integer | Height of the barcode in millimeters, maximum 1000 (a bigger value is ignored). Example: {d.number:barcode(qrcode, height:10)} |
| scale | integer | Barcode quality (1-10). Multiplies width and height for higher resolution. The final image cannot exceed 25 million pixels: width:1000, height:1000 works with scale:1 only. Above the limit, the barcode is replaced by the error image. Example: {d.number:barcode(qrcode, scale:3)} |
| includetext | boolean | Display the text (true/false). Example: {d.number:barcode(qrcode, includetext:false)} |
| textsize | integer | Size of the text in points, maximum 100 (a bigger value is ignored). Example: {d.number:barcode(qrcode, textsize:20)} |
| textxalign | string | Horizontal alignment of text: left, center, right, or justify (default: center). Example: {d.number:barcode(qrcode, textxalign:right)} |
| textyalign | string | Vertical alignment of text: below, center, or above (default: below). Example: {d.number:barcode(qrcode, textyalign:above)} |
| rotate | string | Rotate the barcode/text: N (no rotation), R (90° right), L (90° left), I (180°). Example: {d.number:barcode(qrcode, rotate:R)} |
| barcolor | string | Color of the bars in hexadecimal #RRGGBB. Example: {d.number:barcode(qrcode, barcolor:#1FDE25)} |
| textcolor | string | Color of the text in hexadecimal #RRGGBB. Example: {d.number:barcode(qrcode, textcolor:#1FDE25)} |
| backgroundcolor | string | Background color in hexadecimal #RRGGBB. Example: {d.number:barcode(qrcode, backgroundcolor:#1FDE25)} |
| eclevel | string | Error correction level for QR codes: L (Low), M (Medium, default), Q (Quality), H (High). Example: {d.number:barcode(qrcode, eclevel:Q)} |
DOCX Barcode Example
Insert one temporary picture per barcode, then write the tag in its alternative text (right-click the picture > Edit Alt Text, or View Alt Text). This product label has three barcodes: an EAN-13 for retail checkout, a QR code that opens the setup guide, and a GS1-128 with the GTIN and serial number for logistics.
{
"name": "Laptop Pro 14",
"sku": "LP14-16-512",
"ean": "9520012345674",
"gs1": "(01)09520012345674(21)58201734",
"url": "https://carbone.io/documentation/design/advanced-features/barcode.html"
}
Text of template.docx
PRODUCT LABEL
{d.name}
Acme Corporation · SKU {d.sku}
EAN-13 · RETAIL
[Picture: {d.ean:barcode(ean13, scale:6)}]
QR CODE · SETUP GUIDE
[Picture: {d.url:barcode(qrcode, scale:6)}]
GS1-128 · LOGISTICS
[Picture: {d.gs1:barcode(gs1-128, scale:6)}]

Text of report.docx
PRODUCT LABEL
Laptop Pro 14
Acme Corporation · SKU LP14-16-512
EAN-13 · RETAIL
[Picture]
QR CODE · SETUP GUIDE
[Picture]
GS1-128 · LOGISTICS
[Picture]
- Tags in the alternative text:
{d.ean:barcode(ean13, scale:6)},{d.url:barcode(qrcode, scale:6)}and{d.gs1:barcode(gs1-128, scale:6)}. - Write GS1-128 values with the Application Identifiers in parentheses:
(01)for the GTIN,(21)for the serial number. - Carbone keeps the width of the temporary picture and sets the height from the barcode. Give the picture the proportions of the barcode, or add
:imageFit(contain)to fit the barcode inside it. scalesets the resolution, from 1 to 10 (3 by default). At these sizes,scale:6keeps the bars sharp in print.
HTML Barcode Example
To inject a barcode in HTML templates, insert a Carbone tag within the src attribute of an image tag, and chain it with the :barcode formatter, specifying the type as an argument. For example, this will inject the barcode as a Data-URI in SVG format:
<html>
<body>
<h3> QR-CODE: </h3>
<img src="{d.code:barcode(qrcode)}" alt="Barcode" width="200" height="200">
</body>
</html>
You can adjust the dimensions of the barcode in two ways:
- Using the
<img>Tag: Set the width and height attributes directly on the<img>tag. - Using the Barcode Tag: Specify dimensions within the barcode tag options, in millimeters, for example:
{d.code:barcode(qrcode, width:30, height:30)}. See the barcode options.
Barcodes as font
We recommend using the Barcodes as Image solution instead of this older font method.
Fonts support 4 barcodes. Install the font of each type on the computer that edits the template:
| Type | Font | Download |
|---|---|---|
ean13, ean8 |
Code EAN13 | ean13.ttf |
code39 |
Code 3 de 9 | code39.ttf |
code128 (ean128 is the same code) |
Code 128 | code128.ttf |
Barcodes as font example
Write the tag, then apply the barcode font and size to its opening {, or to the whole tag. Carbone replaces the tag with characters that the font draws as bars, in the format of that first bracket: the rest of the tag can stay readable in the template.
{
"name": "Laptop Pro 14",
"ean13": "9520012345674",
"ean8": "95201238",
"sku": "LP14-16-512",
"serial": "SN58201734"
}
Text of template.odt
BARCODE LABELS
{d.name}
Acme Corporation · Warehouse and retail
Retail box
EAN-13
{d.ean13:barcode(ean13)}
USB-C charger
EAN-8
{d.ean8:barcode(ean8)}
SKU
Code 39
{d.sku:barcode(code39)}
{d.sku}
Serial number
Code 128
{d.serial:barcode(code128)}
{d.serial}

Text of report.odt
BARCODE LABELS
Laptop Pro 14
Acme Corporation · Warehouse and retail
Retail box
EAN-13
9FMKALC*defghe+
USB-C charger
EAN-8
:JFCA*bcdi+
SKU
Code 39
*LP14-16-512*
LP14-16-512
Serial number
Code 128
ÑSNÌZ41BsÓ
SN58201734
- Tags:
{d.ean13:barcode(ean13)},{d.ean8:barcode(ean8)},{d.sku:barcode(code39)}and{d.serial:barcode(code128)}. - Send EAN values with all their digits, check digit included: 13 for
ean13, 8 forean8. Code 39 accepts uppercase letters, digits, spaces and- . $ / + %. An invalid value prints nothing. - The EAN font prints the digits under the bars. The Code 39 and Code 128 fonts print bars only: add the value as text, like
{d.sku}here. - Converting the report, to PDF for example, needs the fonts on the converter.