Barcode Generation Guide

Last updated: October 6, 2025

Barcode Generation Guide

Generate various types of barcodes in your document templates for tracking, identification, and automation.

Table of Contents

Supported Barcode Types

DataMagik Document Designer supports the following barcode formats:

TypeFunctionUse CaseCode 128code128General purpose, alphanumericCode 39code39Industrial, alphanumericQR CodeqrcodeURLs, large data, mobile scanningData MatrixdatamatrixSmall items, compact encodingEAN-13ean13Retail products (13 digits)PDF417pdf417Large data capacity, 2D

All barcodes are rendered as base64-encoded images embedded directly in your HTML/PDF.

Code 128

Code 128 is a high-density linear barcode supporting all ASCII characters. Ideal for general-purpose applications.

Basic Syntax

{{code128 .BarcodeData width height}}

Examples

Simple Barcode:

<div class="barcode-container">
  <p>Order Number:</p>
  {{code128 .OrderNumber 300 100}}
</div>

Sample Data:

{
  "OrderNumber": "ORD-2025-12345"
}

Multiple Barcodes:

<div class="shipping-label">
  <h3>Shipping Label</h3>
  
  <div class="barcode-section">
    <p>Order ID:</p>
    {{code128 .OrderID 250 80}}
  </div>
  
  <div class="barcode-section">
    <p>Tracking Number:</p>
    {{code128 .TrackingNumber 300 100}}
  </div>
  
  <div class="barcode-section">
    <p>Customer ID:</p>
    {{code128 .CustomerID 200 80}}
  </div>
</div>

Sample Data:

{
  "OrderID": "ORD-54321",
  "TrackingNumber": "1Z999AA10123456784",
  "CustomerID": "CUST-001"
}

Size Recommendations

  • Small labels: 200x60 pixels
  • Standard labels: 300x100 pixels
  • Large labels: 400x150 pixels

Supported Characters

Code 128 supports all ASCII characters (0-127):

  • Letters: A-Z, a-z
  • Numbers: 0-9
  • Special characters: -_.*/, etc.

Code 39

Code 39 is widely used in automotive and defense industries. Supports uppercase letters and some special characters.

Basic Syntax

{{code39 .BarcodeData width height}}

Examples

Product Code:

<div class="product-label">
  <h2>{{.ProductName}}</h2>
  <p>Product Code:</p>
  {{code39 .ProductCode 300 100}}
</div>

Sample Data:

{
  "ProductName": "Industrial Widget",
  "ProductCode": "PROD-ABC-123"
}

Asset Tracking:

<div class="asset-tag">
  <h3>Asset Tag</h3>
  <p>Asset ID: {{.AssetID}}</p>
  {{code39 .AssetID 250 90}}
  
  <p>Location: {{.Location}}</p>
  <p>Department: {{.Department}}</p>
</div>

Sample Data:

{
  "AssetID": "ASSET-2025-001",
  "Location": "Warehouse B",
  "Department": "Operations"
}

Character Constraints

Code 39 automatically converts to uppercase and supports:

  • Letters: A-Z (automatically converted from lowercase)
  • Numbers: 0-9
  • Special: - (dash), . (period), $/+%, space

Note: Input is automatically converted to uppercase.

QR Codes

QR (Quick Response) codes are 2D barcodes ideal for URLs, contact information, and data that needs to be scanned by smartphones.

Basic Syntax

{{qrcode .Data size}}

Examples

Website URL:

<div class="qr-section">
  <p>Scan to visit our website:</p>
  {{qrcode .WebsiteURL 200}}
</div>

Sample Data:

{
  "WebsiteURL": "https://www.example.com"
}

Product Information:

<div class="product-card">
  <h3>{{.ProductName}}</h3>
  <p>Price: ${{.Price}}</p>
  
  <div class="qr-code">
    <p>Scan for details:</p>
    {{qrcode .ProductURL 180}}
  </div>
</div>

Sample Data:

{
  "ProductName": "Premium Widget",
  "Price": 99.99,
  "ProductURL": "https://example.com/products/widget-123"
}

Contact Card (vCard):

<div class="business-card">
  <h2>{{.Name}}</h2>
  <p>{{.Title}}</p>
  <p>{{.Email}}</p>
  <p>{{.Phone}}</p>
  
  <div class="qr-contact">
    <p>Scan to save contact:</p>
    {{qrcode .VCard 200}}
  </div>
</div>

Sample Data:

{
  "Name": "John Doe",
  "Title": "Sales Director",
  "Email": "john@example.com",
  "Phone": "+1-555-1234",
  "VCard": "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nTEL:+1-555-1234\nEMAIL:john@example.com\nEND:VCARD"
}

Event Ticket:

<div class="ticket">
  <h1>{{.EventName}}</h1>
  <p>Date: {{.Date | dateFormat "January 2, 2006"}}</p>
  <p>Ticket #: {{.TicketNumber}}</p>
  
  <div class="ticket-qr">
    <p>Scan at entrance:</p>
    {{qrcode .TicketCode 250}}
  </div>
</div>

Size Recommendations

  • Small QR: 150x150 pixels (simple URLs)
  • Medium QR: 200x200 pixels (standard use)
  • Large QR: 300x300 pixels (complex data, long URLs)

Data Capacity

QR codes can store:

  • Numeric: Up to 7,089 characters
  • Alphanumeric: Up to 4,296 characters
  • Binary: Up to 2,953 bytes

Data Matrix

Data Matrix codes are compact 2D barcodes perfect for small items and high-density data storage.

Basic Syntax

{{datamatrix .Data size}}

Examples

Component Tracking:

<div class="component-label">
  <p>Component ID:</p>
  {{datamatrix .ComponentID 100}}
  <p>{{.ComponentID}}</p>
</div>

Sample Data:

{
  "ComponentID": "COMP-2025-ABC-789"
}

Medical Device Labeling:

<div class="medical-label">
  <h3>{{.DeviceName}}</h3>
  
  <div class="datamatrix-section">
    <p>Device Identifier (UDI):</p>
    {{datamatrix .UDI 120}}
  </div>
  
  <p>Serial: {{.SerialNumber}}</p>
  <p>Lot: {{.LotNumber}}</p>
  <p>Exp: {{.ExpirationDate | dateFormat "2006-01-02"}}</p>
</div>

Sample Data:

{
  "DeviceName": "Surgical Instrument",
  "UDI": "(01)00312345678906(17)250930(10)ABC123",
  "SerialNumber": "SN123456",
  "LotNumber": "LOT2025",
  "ExpirationDate": "2025-09-30"
}

Size Recommendations

  • Very small: 80x80 pixels
  • Small: 100x100 pixels
  • Medium: 150x150 pixels
  • Large: 200x200 pixels

Use Cases

  • Small electronic components
  • Medical device identification
  • Pharmaceutical packaging
  • Manufacturing part tracking

EAN-13

EAN-13 (European Article Number) is the standard barcode for retail products worldwide.

Basic Syntax

{{ean13 .ProductCode width height}}

Format Requirements

EAN-13 requires exactly 12 or 13 digits:

  • 12 digits: Checksum is calculated automatically
  • 13 digits: Last digit is the checksum (will be recalculated)

Examples

Product Label:

<div class="product-label">
  <h2>{{.ProductName}}</h2>
  <p>Price: ${{.Price | printf "%.2f"}}</p>
  
  <div class="barcode">
    {{ean13 .EAN 300 100}}
  </div>
  
  <p class="ean-number">{{.EAN}}</p>
</div>

Sample Data:

{
  "ProductName": "Wireless Mouse",
  "Price": 29.99,
  "EAN": "5901234123457"
}

Retail Price Tag:

<div class="price-tag">
  <div class="product-info">
    <p class="name">{{.Name}}</p>
    <p class="price">${{.Price | printf "%.2f"}}</p>
  </div>
  
  <div class="barcode-section">
    {{ean13 .EAN13Code 250 80}}
  </div>
  
  <div class="additional-info">
    <p>SKU: {{.SKU}}</p>
    <p>Department: {{.Department}}</p>
  </div>
</div>

Sample Data:

{
  "Name": "Premium Coffee Beans",
  "Price": 15.99,
  "EAN13Code": "0123456789012",
  "SKU": "COF-001",
  "Department": "Grocery"
}

Valid EAN-13 Examples

0123456789012  (12 digits - valid)
5901234123457  (13 digits - valid)
8712345678900  (13 digits - valid)

Common Errors

  • ❌ Too few digits: 12345 (needs 12-13)
  • ❌ Too many digits: 12345678901234 (max 13)
  • ❌ Contains letters: ABC123456789
  • ✅ Correct: 0123456789012

PDF417

PDF417 is a stacked linear barcode with high data capacity, commonly used for identification documents.

Basic Syntax

{{pdf417 .Data width height}}

Examples

Driver's License:

<div class="id-card">
  <h3>Driver License</h3>
  
  <div class="photo">
    <img src="{{.PhotoURL}}" alt="Photo">
  </div>
  
  <div class="details">
    <p>Name: {{.Name}}</p>
    <p>License #: {{.LicenseNumber}}</p>
    <p>DOB: {{.DateOfBirth | dateFormat "01/02/2006"}}</p>
    <p>Expires: {{.ExpirationDate | dateFormat "01/02/2006"}}</p>
  </div>
  
  <div class="barcode">
    {{pdf417 .EncodedData 400 150}}
  </div>
</div>

Sample Data:

{
  "PhotoURL": "data:image/jpeg;base64,...",
  "Name": "JOHN DOE",
  "LicenseNumber": "D1234567",
  "DateOfBirth": "1985-05-15",
  "ExpirationDate": "2028-05-15",
  "EncodedData": "ANSI 6360010102DL00410288ZA03290015DLDAQD1234567..."
}

Shipping Label:

<div class="shipping-label">
  <h2>Express Shipping</h2>
  
  <div class="addresses">
    <div class="from">
      <p><strong>From:</strong></p>
      <p>{{.SenderName}}</p>
      <p>{{.SenderAddress}}</p>
    </div>
    
    <div class="to">
      <p><strong>To:</strong></p>
      <p>{{.RecipientName}}</p>
      <p>{{.RecipientAddress}}</p>
    </div>
  </div>
  
  <div class="barcode-2d">
    {{pdf417 .ShippingData 450 180}}
  </div>
  
  <p class="tracking">Tracking: {{.TrackingNumber}}</p>
</div>

Size Recommendations

  • Compact: 300x100 pixels
  • Standard: 400x150 pixels
  • Large: 500x200 pixels

Data Capacity

PDF417 can encode:

  • Up to 1,850 text characters
  • Up to 2,710 numeric digits
  • Up to 1,108 bytes of binary data

Generic Barcode Function

Use the generic barcode function to dynamically specify barcode type:

Syntax

{{barcode "type" .Data width height}}

Examples

Dynamic Barcode Type:

<div class="dynamic-barcode">
  {{barcode .BarcodeType .BarcodeData 300 100}}
</div>

Sample Data:

{
  "BarcodeType": "code128",
  "BarcodeData": "DYNAMIC-123"
}

Conditional Barcode Selection:

{{if eq .Region "US"}}
  {{code128 .ProductCode 300 100}}
{{else if eq .Region "EU"}}
  {{ean13 .EAN 300 100}}
{{else}}
  {{qrcode .ProductURL 200}}
{{end}}

Real-World Examples

Example 1: Complete Shipping Label

<!DOCTYPE html>
<html>
<head>
  <title>Shipping Label</title>
  <style>
    body { font-family: Arial, sans-serif; padding: 20px; }
    .label { border: 2px solid #000; padding: 20px; width: 600px; }
    .section { margin: 15px 0; padding: 10px; border-bottom: 1px solid #ddd; }
    .barcode-container { text-align: center; margin: 20px 0; }
    .addresses { display: flex; justify-content: space-between; }
    .address-block { flex: 1; }
  </style>
</head>
<body>
  <div class="label">
    <!-- Header -->
    <div class="section">
      <h1>{{.Carrier | upper}} - {{.ServiceType}}</h1>
      <p>Ship Date: {{.ShipDate | dateFormat "Monday, January 2, 2006"}}</p>
    </div>
    
    <!-- Addresses -->
    <div class="section addresses">
      <div class="address-block">
        <h3>FROM:</h3>
        <p><strong>{{.Sender.Name}}</strong></p>
        <p>{{.Sender.Street}}</p>
        <p>{{.Sender.City}}, {{.Sender.State}} {{.Sender.Zip}}</p>
        <p>{{.Sender.Country}}</p>
      </div>
      
      <div class="address-block">
        <h3>TO:</h3>
        <p><strong>{{.Recipient.Name}}</strong></p>
        <p>{{.Recipient.Street}}</p>
        <p>{{.Recipient.City}}, {{.Recipient.State}} {{.Recipient.Zip}}</p>
        <p>{{.Recipient.Country}}</p>
      </div>
    </div>
    
    <!-- Tracking Barcode -->
    <div class="section barcode-container">
      <h2>Tracking Number</h2>
      {{code128 .TrackingNumber 450 120}}
      <p style="font-size: 18px; letter-spacing: 2px;">{{.TrackingNumber}}</p>
    </div>
    
    <!-- Package Info -->
    <div class="section">
      <h3>Package Information</h3>
      <p>Weight: {{.Weight}} lbs</p>
      <p>Dimensions: {{.Length}}" x {{.Width}}" x {{.Height}}"</p>
      <p>Reference: {{.ReferenceNumber}}</p>
    </div>
    
    <!-- QR Code for Mobile Tracking -->
    <div class="section barcode-container">
      <p>Scan to track:</p>
      {{qrcode .TrackingURL 150}}
    </div>
  </div>
</body>
</html>

Example 2: Product Label with Multiple Barcodes

<div class="product-label">
  <div class="header">
    <h1>{{.ProductName | upper}}</h1>
    <p class="category">{{.Category | title}}</p>
  </div>
  
  <div class="price-section">
    <p class="price">${{.Price | printf "%.2f"}}</p>
    {{if .OnSale}}
    <p class="original-price">${{.OriginalPrice | printf "%.2f"}}</p>
    <p class="savings">SAVE ${{.Savings | printf "%.2f"}}</p>
    {{end}}
  </div>
  
  <div class="barcodes">
    <!-- EAN-13 for retail scanning -->
    <div class="barcode-section">
      <p>Retail Barcode:</p>
      {{ean13 .EAN 300 90}}
    </div>
    
    <!-- Internal SKU barcode -->
    <div class="barcode-section">
      <p>SKU: {{.SKU}}</p>
      {{code128 .SKU 250 70}}
    </div>
    
    <!-- QR code for product info -->
    <div class="barcode-section">
      <p>Product Info:</p>
      {{qrcode .ProductInfoURL 120}}
    </div>
  </div>
  
  <div class="details">
    <p>Size: {{.Size}}</p>
    <p>Color: {{.Color}}</p>
    <p>Stock: {{.StockQuantity}} units</p>
  </div>
</div>

Example 3: Event Badges with QR Codes

<div class="event-badge">
  <div class="badge-header">
    <h1>{{.EventName}}</h1>
    <p>{{.EventDate | dateFormat "January 2-3, 2006"}}</p>
  </div>
  
  <div class="attendee-info">
    <h2>{{.AttendeeName | title}}</h2>
    <p class="company">{{.Company}}</p>
    <p class="title">{{.JobTitle | title}}</p>
  </div>
  
  <div class="badge-type {{.BadgeType | lower}}">
    <p>{{.BadgeType | upper}}</p>
  </div>
  
  <div class="qr-section">
    <p>Check-in Code:</p>
    {{qrcode .AttendeeID 200}}
  </div>
  
  <div class="access-info">
    {{if .HasVIPAccess}}
    <p class="vip">✓ VIP ACCESS</p>
    {{end}}
    {{if .HasWorkshopAccess}}
    <p>✓ Workshop Access</p>
    {{end}}
    {{if .HasNetworkingAccess}}
    <p>✓ Networking Events</p>
    {{end}}
  </div>
  
  <div class="barcode-footer">
    {{code128 .BadgeID 250 60}}
  </div>
</div>

Best Practices

Sizing Guidelines

  1. Test for Scannability: Larger is generally better for scanning reliability
  2. Minimum Sizes:
  • Code 128/39: 200x60 pixels minimum
  • EAN-13: 250x80 pixels minimum
  • QR Codes: 150x150 pixels minimum
  • Data Matrix: 80x80 pixels minimum

Data Guidelines

  1. Validate Input: Ensure data matches barcode type requirements
  2. Keep It Simple: Shorter data encodes more reliably
  3. Test Scanning: Always test with actual scanners before production
  4. Include Human-Readable: Display the encoded data as text below barcode

Layout Tips

  1. White Space: Leave adequate white space around barcodes (quiet zone)
  2. Contrast: Use high contrast (black on white is ideal)
  3. Avoid Backgrounds: Don't place barcodes over patterned backgrounds
  4. Print Quality: Ensure high-resolution printing for physical labels

Error Handling

Barcodes that fail to generate will show an error message. Common causes:

  • Invalid characters for barcode type
  • Data too long for barcode capacity
  • Invalid EAN-13 format (wrong number of digits)

Troubleshooting

Barcode Not Scanning

  1. Check size: Increase width/height
  2. Verify data: Ensure data matches barcode type requirements
  3. Check contrast: Use black barcode on white background
  4. Test different scanners: Some scanners work better with certain formats

Barcode Not Displaying

  1. Check syntax: Verify function name and parameters
  2. Validate data: Ensure data field exists in sample JSON
  3. Check quotes: Use correct quote types in template

Next Steps

Pro Tip: Always include human-readable text below barcodes as a backup for manual entry!

Was this page helpful?