Barcodes

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:

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

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:

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

Barcode Properties

PropertyTypeDescription
_typestring
Must be set to "barcode"
datastring
Required. Text to encode in the barcode
formatstring
Optional. Barcode format (e.g. "CODE128", "EAN13", "UPC"). Default is "CODE128"
colorstring
Optional. Foreground color in hex format (e.g. "#000000"). Default is black
backgroundstring
Optional. Background color in hex format (e.g. "#ffffff"). Default is white
barWidthnumber
Optional. Width of the barcode bars in pixels. Default is 2
barHeightnumber
Optional. Height of the barcode bars in pixels. Default is 100
marginnumber
Optional. Margin around the barcode in pixels. Default is 10
showTextboolean
Optional. Whether to display the data text below the barcode. Default is true
textDistancenumber
Optional. Distance between barcode and text. Default is 1
fontSizenumber
Optional. Font size for the display text. Default is 23

Examples

Simple Barcode

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

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

Simple Barcode Example

Custom Styled Barcode

This preview shows the tag fields exactly as they appear in the TemplateDocs UI.

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
Barcodes - TemplateDocs Documentation