Skip to content

TSPL

A library to generate TSPl layouts from a JSON-object.

A layout contains two parts;

  • Parameters: the meta information about the label; width, height, dpi, etc. Check Parameters for the available parameters
  • Template: an array that contains all the fields on the label. Check Fields for the available fields
{
    "parameter1":"value",
    "parameter2":"value",
    "parameter3":"value",
    //etc..
    "aTemplate":[
        {
            //field
        },
        {
            //field
        }
    ]
}

Parameters

These parameters should be provided in the root of the layout object. If you pass one of these parameters to the library, it will be used, otherwise the values from the column default will be used.

Parameter Default Type Description
iDpi 8 Int Dots per mm. Check your printer model for the right dpmm (set 8 for 200dpi printers, and 12 for 300dpi printers). Check #Dpi below for more information
iDefaultFontSize 5 Int Default font size, default is the best most cases
sName Layout 1 String Pretty name to recognize the layout in the UI
sID LAYOUT1 String A (unique) layout name, under which the layout is stored in the printer memory. Make sure it's unique when multiple layouts are used with this printers. Always use "LAYOUT" as filename. "LAYOUT1","LAYOUT2","LAYOUT3", etc.
iMediaDarkness 4 Int Change the intensity of the printing
iHeightMm 10 Int (mm) Outer height of the label
iWidthMm 72 Int (mm) Outer height of the label (include the loop!)
iPaddingLeft 0 Int (dots) Set the horizontal print origin within the label.
Example: value 16 will set x0 to 2mm from the left
iPaddingTop 0 Int (dots) Set the vertical print origin within the label.
Example: value 8 will set y0 to 1mm from the left
iMarginLeft 0 Int (mm) Shift the printing position horizontally
iMarginTop 0 Int (mm) Shift the printing position vertically
iGapMm 2.7 Float(mm) The exact space between labels.
aInversion [1,0] Array Whether to flip the layout horizontally and/or vertically. Check #Inversion below which value you need.
sCodePage UTF-8 String Default codepage
iPrintSpeed 2 Int Print speed
iOffsetMm -4 Int (mm) Some printing offset setting, -4 just works
bTear true Bool For tear off labels
bCut false Bool For cutting labels
aTemplate [] Array This array should contain one or more Field objects

Dpi

dpi dots per mm
200dpi 8 dots per mmm
300dpi 12 dots per mm

Labelprinters come in two resolutions; 200dpi and 300dpi. Check the model specifications to see which resolution your printer has.
All (dot)values should be measured at 8 dots per mm. If you set this parameter to 12, these values will be automatically be converted (multiplied by 1.5). For example; if you want to place a text 1mm from the left, use x:8. If iDpi is set to 12, the library will convert this to x:12

Inversion

value result default
[0,0] y inverted, x normal
[1,0] y normal, x normal x
[1,1] y normal, x inverted
[0,1] y inverted, x inverted

Fields

Fields are objects that should be added to aTemplate. They need at least a type, and a position defined in x and y.

Content

All fields expect a content-attribute, except graphic fields (rectangle, line, circle, debug). You can put a hard coded value in it, or a Variable.

Variables

Variables are inserted using placeholders. These always have the format %%UPPERCASE_KEYWORD%%.

Available fields

Text

A field meant for a single-line value

{
    "type":"text",
    "x":8,
    "y":42,
    "content":"%%SELLING_PRICE%%"
},

Textblock

Very similar to text, but with a specific width and height.

{
    "type":"textblock",
    "x": 180,
    "y": 40,
    "width": 176,
    "height": 40,
    "content":"%%DESCRIPTION%%"
}

Optional fields for Text and Textblock

Attribute Description Default (when not specified)
font_family pick a alternative font between 1 and 8 0
font_size change the font size 5
text_align center,right left
rotation 90,180 or 270 0
filter Apply a filter to the content. Check Filters for
max The maximum of characters in this string. If string is longer than (length of content + suffix), the text will be cut short and the suffix will apply.
suffix The characters that are placed at the end of a text when max is applied ..

Barcode

Print a barcode on the label

{
    "type":"barcode",
    "x":8,
    "y":8,
    "content":"%%ARTICLE_NUMBER%%"
},

Optional parameters for barcodes

Attribute Description Default (when not specified)
barcode_type The barcode type. Check the TSPL documentation for options. Don't change this unless you know what you're doing. "128"
height The height of the barcode 15
text_align Print the value of the barcode in text below it. left, center or right. When empty, no text will be shown 0
barcode_align Align the barcode
rotation Rotate the barcode. 90, 180 or 270 0
bar_narrow The width of the narrow bars in the barcode. Check the TSPL documentation for options. Don't change this unless you know what you're doing.
bar_wide The width of the wide bars in the barcode. Check the TSPL documentation for options. Don't change this unless you know what you're doing.

Datamatrix

{
    "type":"datamatrix",
    "x":8,
    "y":8,
    "size": 160, //the size of the datamatrix in dots
    "content":"%%ARTICLE_NUMBER%%"
}

QR code

{
    "type":"qrcode",
    "x":8,
    "y":8,
    "content":"%%ARTICLE_NUMBER%%"
}
Attribute Description Default (when not specified)
ecc The barcode type. Check the TSPL documentation for options. Don't change this unless you know what you're doing. H
cell_width The size of the blocks of which 3
rotation Rotate the qr code. 90, 180 or 270 0
mode A
model 2
mask 7

Line

{
    "x":8,
    "y":8,
    "width":80,
    "height":1
}

Rectangle

{
    "type":"rectangle",
    "x1":8,
    "y1":8,
    "x2":16,
    "y2":16,
    "border_width":2,
    "border_radius":2
},

Circle

{
    "x":8, //left
    "y":8, //top
    "width":80, //outer width of the circle
    "border":2 //default: 1
}

Debug

This prints vertical lines every 1 mm, and a single, horizontal line in the middle.

{
    "type":"debug"
},

Rectangle

{
    "type":"rectangle",
    "x1":1,
    "y1":1,
    "x2":175,
    "y2":80,
    "border_width":2,
    "border_radius":2
},

Available variables