Skip to content

Label Templates

James Shepherdson edited this page Oct 25, 2020 · 1 revision

LabelTool uses JSON-formatted .lbl template files to define label templates. At the moment, LabelTool does not include a graphical template editor (although this is a desired feature for a future release).


Template File Format

This document describes the formatting and possible elements of a LabelTool .lbl template file.

{
    "metadata": {
        "version": 1,
    },
    "physicalProperties": {
        "manufacturer": "LabTag",
        "productName": "JTTA-52NOT",
        "width": 488,
        "height": 188
    },
    "elements": [
        {
            "type": "text",
            "x": 190,
            "y": 20,
            "width": 215,
            "height": 150,
            "rotation": 0,
            "value": "<span style=\"font-size: 18px; font-family: Arial;\">${initials} #{today}</span><br/><span style=\"font-size: 36px; font-weight: bold; font-family: Arial;\">${prefix}${number}</span><br/><span style=\"font-size: 20px; font-weight: bold; font-family: Arial;\">${details}</span><br/>"
        },
        {
            "type": "barcode",
            "x": 460,
            "y": 42,
            "rotation": 90,
            "scale": 3,
            "value": "#{uuid}"
        },
        {
            "type": "text",
            "x": 18,
            "y": 28,
            "width": 130,
            "height": 130,
            "alignment": "center",
            "value": "<span style=\"font-size: 24px; font-family: Arial;\">${prefix}</span><br><span style=\"font-size: 42px; font-family: Arial; font-weight: bold;\">${number}</span>"
        },
    ]
}

Structure

  • The root element of the JSON file must be a dictionary.
  • The metadata key must be a dictionary, which contains a single key, version, with a value of 1.
  • physicalProperties must be a dictionary, with the following keys:
    • manufacturer (optional) — the company that manufactures the physical labels that this template is designed for
    • productName (optional) — the name, catalog number, or product ID of the physical labels that this template is designed for
    • width — the width of printable area of the label, in dots
      • for example, for a 300 dpi printer, a label that is 2 inches wide should have a value of 600
    • height — the height of the printable area of the label, in dots
  • elements must be an array of zero or more dictionaries, each of which must contain:
    • type — currently either "text" or "barcode"
    • x — the x-coordinate, in dots, of the corner of the element's bounding box
    • y — the y-coordinate, in dots, of the corner of the element's bounding box
    • For text elements:
      • width — the width, in dots, of the element's bounding box
      • height — the height, in dots, of the element's bounding box
      • alignment (optional) — the alignment of text within the bounding box (e.g. "leftTop", "centerMiddle", "rightBottom", etc.)
      • rotation (optional) — the rotation of the bounding box
    • For barcode elements:
      • scale — the scale of the data blocks in the barcode
      • rotation (optional) — the rotation of the bounding box
    • value — the textual value of the element (a string, either of plain text or including HTML formatting tags)

Variable Fields

  • Element value fields may contain any number of variable label fields
  • User-provided variable fields are denoted by the form ${variable_name}
  • Automatically-computed variable fields are denoted by the form #{variable_name}
    • Currently, two computed variable fields are available: #{today} and #{uuid}

Text Formatting

  • text elements can be formatted using HTML and CSS. This HTML and CSS cannot modify text structure or placement, only text styling.
    • Under the hood, an NSAttributedString is created using the built-in init(html:documentAttributes:) method.
    • The specific CSS traits and HTML tags that are supported are poorly-documented. Your best bet is simply to test a given tag, and see if it works.

Clone this wiki locally