1 Basic usage
To print the value of the Store_name
key ("Star Cafe"), specify a character string containing a replacing specifier.
2 Combination with markup tags
To print the value of the order_number
key ("#2-007") and the value of the time
key ("10/16 11:13PM") in a two-column layout, specify a character string containing replacing specifiers in the parameter of the [column]
tag. Like the left
parameter as shown in this example, normal texts and replacing specifiers can coexist.
In addition, specifying the vl
(variable-left) option automatically reduces the number of characters of a character string that is replaced with the left
parameter even if the number increases, preventing the disruption of the layout.
For details of the option, refer to Tag References.
[column: vl; left Order ${order_number}; right ${time}]
3 Field data of array elements
To print the field data of array elements, specify the template area to repeat using the [templateArray]
tag. Specify the [templateArray: start]
tag at the start of the repeat and the [templateArray: end]
tag at the end of the repeat.
A character string containing replacing specifiers that specify the field data of array elements (item.list
key values) written in the area enclosed within the [templateArray]
tag is printed repeatedly as many times as the number of array elements.
[templateArray: start]
[column: vl; left ${item_list.quantity%-2d} ${item_list.name}; right ${item_list.unit_price%6.2lf}]
[templateArray: end]\
4 Number format specification
To print the numeric-type subtotal
key value (8.24) in a specified format, specify a character string containing a replacing specifier that specifies the number format.
[column: vl; left Subtotal; right ${subtotal%6.2lf}]
5 Combination with markup tags
To print the value of the transaction_id
key ("0123456789"), specify a character string containing a replacing specifier in the data
parameter of the [barcode]
tag.
[barcode: type code39; data ${transaction_id}; height 15mm; module 0; hri]\
To convert the template and field data created in this section into printer commands, use the following library or tool.
Sample code
Field data: JSON
{
"store_name" : "Star Cafe",
"order_number" : "#2-007",
"time" : "10/16 11:13PM",
"sales_type" : "Walk-in",
"server" : "Jane",
"transaction_id" : "0123456789",
"item_list" : [
{
"name" : "Vanilla Latte",
"unit_price" : 4.99,
"quantity" : 1
},
{
"name" : "Chocolate Chip Cookie",
"unit_price" : 3.25,
"quantity" : 1
}
],
"subtotal" : 8.24,
"tax" : 0.73,
"total" : 8.97,
"credit_card_number" : "VISA 0123",
"approval_code" : "OK2443",
"amount" : 8.97,
"address" : "123 Star Road, City,\nState 12345",
"tel" : "123-456-7890",
"mail" : "info@star-m.jp",
"url" : "star-m.jp"
}
Template: Star Document Markup
[align: center]\
[font: a]\
[image: url https://star-emea.com/wp-content/uploads/2015/01/logo.jpg; width 60%; min-width 48mm]\
[magnify: width 2; height 2]
${store_name}\
[plain]\
[align: left]\
[column: vl; left Order ${order_number}; right ${time}]
[column: vl; left Sale for ${sales_type}; right Served by ${server}]\
Transaction #${transaction_id}
[fixedWidth: text ------------------------------------------------]\
[templateArray: start]
[column: vl; left ${item_list.quantity%-2d} ${item_list.name}; right ${item_list.unit_price%6.2lf}]
[templateArray: end]\
[fixedWidth: text ------------------------------------------------]\
[column: vl; left Subtotal; right ${subtotal%6.2lf}]
[column: vl; left Tax; right ${tax%6.2lf}]
[bold: on]\
[column: vl; left Total; right ${total%6.2lf}]\
[bold: off]\
[fixedWidth: text ------------------------------------------------]\
[column: vl; left ${credit_card_number}; right ${total%6.2lf}]
[column: vl; left Approval Code; right ${approval_code}]\
[fixedWidth: text ------------------------------------------------]\
[column: vl; left Amount; right ${amount%6.2lf}]
[column: vl; left Total; right ${total%6.2lf}]\
[fixedWidth: text ------------------------------------------------]\
Signature\
[align: center]\
------------------------
${address}
${tel}
${mail}
${url}\
[fixedWidth: text ------------------------------------------------]\
Powered by Star Micronics\
[barcode: type code39; data ${transaction_id}; height 15mm; module 0; hri]\
[cut: feed; partial]
Template
A template is a print layout defined by a combination of fixed printing data and replacing specifiers, created with the Star Document Markup.
You can define a field (replacement area) in the template, which is a print layout, using a replacing specifier. A value with the same key from field data in JSON format can be substituted for a replacing specifier.
Specify a replacing specifier in plain text. A replacing specifier can coexist with a normal text.
Date:${date} Time:${time}
Replacing specifier format
A key character string enclosed between ${ and }, like "${key-string}," is treated as a replacing specifier.
If there is a key that matches 'key-string' in the field data, the text in the "${key-string}" area is replaced with the key value.
If there is no matching key, printing is conducted with the "${key-string}" area ignored.
Key specifier
You can specify a key in the field data to identify the field data with which you want to replace.
Only ASCII characters are allowed in keys.
Case of a nested element
To specify a nested element, combine keys with a period (.).
Example of specifying a nested element
Field data
{
"store" : {
"name" : "Star Store",
"address" : "123 Star Road, City, State 12345"
}
}
Case of an array element
By specifying an array element as the key for use with the key specifier, you can perform replacements for a single field based on the number of elements in the array.
In this case, you also need to define the range of the template to be repeated for the number of array elements.
The [templateArray]
tag, which specifies the repeat range when array field data exists, allows the range to be repeated as many times as the number of array elements.
In the example below, keys of child elements of an array element (character string type and numeric type) are specified using key specifiers, and the repetition of array elements is specified by the [templateArray]
tag. As a result, the target repeat area enclosed within the [templateArray]
tag is printed only four times, the number of array elements in the field data.
Template
[templateArray: start]
[column: left ${item_list.name}; right ${item_list.unit_price%6.2lf}
[underline: on]\
[column: left ; right x${item_list.quantity}]
[underline: off]\
[templateArray: end]
[cut: feed; partial]
Field data
{
"item_list" : [
{
"name" : "BLT",
"unit_price" : 13.0,
"quantity" : 1
},
{
"name" : "Chicken Noodle",
"unit_price" : 7.5,
"quantity" : 1
},
{
"name" : "Caesar salad",
"unit_price" : 10.0,
"quantity" : 2
},
{
"name" : "Coffee",
"unit_price" : 3.5,
"quantity" : 2
}
]
}
Print result
Number format specifier
If a field data value is a numeric type, you can specify the display format using a number format specifier. A number format specifier is a subset of a format specifier in printf function in C language. A number format specifier can be omitted. If omitted, the value is used as a character string without being converted.
Option | Meaning |
♯ | Converts to another format (Adds 0x at the beginning for a hexadecimal value). |
0 | Fills with zeros. |
SP (space character) | Adds a space character to the left if the value is positive in a signed conversion. |
+ | Adds a plus sign if the value is positive. |
− | Aligns to the left. |
Number of displayed digits | [ Total number of display digits ] . [ Number of decimal places ] |
Output format specifier | Meaning |
d | Outputs a signed integer in decimal. |
u | Outputs an unsigned integer in decimal. |
f | Outputs a real number. |
x | Outputs an integer in lower-case hexadecimal. |
X | Outputs an integer in upper-case hexadecimal. |
ld | Outputs a signed long integer in decimal. |
lu | Outputs an unsigned long integer in decimal. |
lf | Outputs a double-precision real number. |
lx | Outputs a long integer in lower-case hexadecimal. |
lX | Outputs a long integer in upper-case hexadecimal. |
Escape characters
When you want to print ${
signifying the start of a replacing specifier, add a ; to the end for escape (${;
).
To include the following characters, which have special meanings for the template printing function, in a field data key, when using them in a key specifier, place a \\ before the characters for escape.
Template printing function-compatible tags
You can define a field using a replacing specifier in the following tags.
Tag | Parameter |
Plain text | |
[barcode] | data |
[column] | left, right, short |
[fixedWidth] | text |