Barcode Syntax

It's easy to add barcodes to your documents with TemplateDocs. The barcode tag syntax is the same as a simple text tag:

{{ MyBarcode }}

Provide the barcode details in your JSON data using the barcode object structure shown below:

{
  "MyBarcode": {
    "_type": "barcode",
    "data": "123456789012"
  }
}

This will create a barcode that encodes "123456789012" with default settings (CODE128 format, black on white, auto-sized).

Barcode Example

Using Image Placeholders

Barcodes can also be inserted using image placeholders. This allows you to replace existing images in your template with generated barcodes. To mark an image as a placeholder, insert a tag in its alt text. Then use the same JSON data as you would for a regular barcode tag. For example:

{
  "MyPlaceholder": {
    "_type": "barcode",
    "data": "123456789012"
  }
}

Barcode Properties

PropertyTypeDescription
_typestringMust be set to "barcode"
datastringRequired. Text to encode in the barcode
formatstringOptional. Barcode format (e.g. "CODE128", "EAN13", "UPC"). Default is "CODE128"
colorstringOptional. Foreground color in hex format (e.g. "#000000"). Default is black
backgroundstringOptional. Background color in hex format (e.g. "#ffffff"). Default is white
barWidthnumberOptional. Width of the barcode bars in pixels. Default is 2
barHeightnumberOptional. Height of the barcode bars in pixels. Default is 100
marginnumberOptional. Margin around the barcode in pixels. Default is 10
showTextbooleanOptional. Whether to display the data text below the barcode. Default is true
textDistancenumberOptional. Distance between barcode and text. Default is 1
fontSizenumberOptional. Font size for the display text. Default is 23

Examples

Simple Barcode

{
  "ProductCode": {
    "_type": "barcode",
    "data": "123456789012"
  }
}

This creates a barcode with default settings (CODE128 format, black on white, auto-sized).

Simple Barcode Example

Custom Styled Barcode

{
  "CustomBarcode": {
    "_type": "barcode",
    "data": "123456789012",
    "format": "EAN13",
    "color": "#2563eb",
    "background": "#e2e8f0",
    "barWidth": 3,
    "barHeight": 120,
    "margin": 15,
    "showText": true,
    "fontSize": 16,
    "textDistance": 15
  }
}

This creates a blue barcode on a light gray background with custom bar dimensions and styling.

Styled Barcode Example

Supported Barcode Formats

Barcode TypeFormat CodeTypical Use CaseCharsetPopularity
Code 128 (auto)CODE128General-purpose, logistics, shipping labelsFull ASCIIVery High
Code 128 ACODE128AIndustrial, system codesControl + upper-case ASCIIMedium
Code 128 BCODE128BGeneral-purpose textUpper + lower-case ASCIIMedium
Code 128 CCODE128CHigh-density numbers (shipping, logistics)Numeric pairsHigh
UPC-AUPCRetail in US/Canada12 digitsVery High
UPC-EUPCESmall-pack retail (US/Canada)6 digits (compressed)High
EAN-13EAN13Retail worldwide13 digitsVery High
EAN-8EAN8Small-pack retail worldwide8 digitsHigh
Code 39CODE39Industrial, automotive, defenseAlphanumericHigh
ITF-14ITF14Carton / packaging (GS1 standard)14 digits (numeric only)High
ITF (generic)ITFLegacy warehouse / internal logisticsNumeric onlyLow
Code 93CODE93Canada Post, niche industrialFull ASCII (compact)Low
MSI-10MSI10Legacy retail/warehouse (mod 10 check)Numeric onlyMedium
MSI-1010MSI1010Legacy retail/warehouse (double mod 10)Numeric onlyLow-Medium
MSI-11MSI11Legacy (mod 11 check)Numeric onlyRare
MSI-1110MSI1110Legacy (mod 11 + mod 10)Numeric onlyRare
CodabarcodabarLibraries, blood banks, older healthcareDigits + A/B/C/DRare
PharmacodepharmacodePharmaceutical packagingNumeric only (1–6 digits)Rare