The Printing Java API supports label printing through a string of printer commands or by invoking a stored format on the printer. The label definitions are defined in groups in the LABELS member of the printer commands and attributes LINEPRINTERCONTROL JSON object. Each label group is an object whose name identifies the group.
The following example is extracted from the standard printer_profiles.JSON file provided by the Honeywell Mobility Android Printing SDK. The LABELS object contains two groups, 2in_FingerprintLabels and 3in_FingerprintLabels. Each group contains two label definition objects, ItemLabel and URL_QRLabel.
"LABELS":
{
"2in_FingerprintLabels":
{
"ItemLabel":
{
"LabelDataStream": "DIR 4:AN 7:PP 30, 120:FT \"Swiss 721 Bold Condensed BT\",16:PT \"ItemName$$\":PP 120,75:BARSET \"CODE128\",3,1,4,150:PB \"ItemNo$$\":PP 280, 260:FT \"Letter Gothic 12 Pitch BT\",14:PT \"ItemNo$$\":PF\r\n",
"VarPostfix": "$$"
},
"URL_QRLabel":
{
"StoreFormat": "INPUT ON\r\nLAYOUT INPUT \"URLQRLABEL.LAY\"\r\nDIR 4:AN 7:PP 100, 20:FT \"Swiss 721 Bold Condensed BT\",16:PT VAR1$:PP 200, 20:FT \"Letter Gothic 12 Pitch BT\",14:PT VAR2$:PP 70,450:BARSET \"QRCODE\",1,1,8,2,2:PB VAR3$\r\nLAYOUT END\r\nINPUT OFF\r\n",
"InvokeFormat": "INPUT OFF\r\nFORMAT INPUT \"#\",\"@\",\"|\"\r\nINPUT ON\r\nLAYOUT RUN \"URLQRLABEL.LAY\"\r\n#qTextLine1$|qTextLine2$|qURL$|@\r\nPF\r\nINPUT OFF\r\n",
"VarPrefix": "q",
"VarPostfix": "$"
}
},
"3in_FingerprintLabels":
{
"ItemLabel":
{
"LabelDataStream": "DIR 4:AN 7:PP 40, 180:FT \"Swiss 721 Bold Condensed BT\",20:PT \"ItemName$$\":PP 150,180:BARSET \"CODE128\",3,1,4,240:PB \"ItemNo$$\":PP 400, 330:FT \"Letter Gothic 12 Pitch BT\",14:PT \"ItemNo$$\":PF\r\n",
"VarPostfix": "$$"
}, "URL_QRLabel":
{
"StoreFormat": "INPUT ON\r\nLAYOUT INPUT \"URLQRLABEL.LAY\"\r\nDIR 4:AN 7:PP 200, 50:FT \"Swiss 721 Bold Condensed BT\",16:PT VAR1$:PP 300, 50:FT \"Letter Gothic 12 Pitch BT\",14:PT VAR2$:PP 105,490:BARSET \"QRCODE\",1,1,13,2,2:PB VAR3$\r\nLAYOUT END\r\nINPUT OFF\r\n",
"InvokeFormat": "INPUT OFF\r\nFORMAT INPUT \"#\",\"@\",\"|\"\r\nINPUT ON\r\nLAYOUT RUN \"URLQRLABEL.LAY\"\r\n#qTextLine1$|qTextLine2$|qURL$|@\r\nPF\r\nINPUT OFF\r\n",
"VarPrefix": "q",
"VarPostfix": "$"
}
}
}
The label definition object may include one or more of the following members:
If you would like to control when to send the commands to store the label format on the printer, you may define a member containing custom commands in the printer settings object and use the sendCustomCommand to send the commands instead of using StoreFormat.
The data for the variables is provided by LabelPrinter.writeLabel method. Therefore, the InvokeFormat string needs to specify variables in place of the data, using the same variable format as described for LabelDataStream.
Each label definition object needs to contain either a LabelDataStream member or an InvokeFormat member. If both members are specified, only the LabelDataStream member is used.
The label related settings were designed so that you may print similar labels for different printers without changing the printing code. In the previous example, the 2in_FingerprintLabels and 3in_FingerprintLabels groups contain the same member names, "ItemLabel" and "URL_QRLabel". One set of labels were designed for 2" printers and the other for 3" printers. The label formats between the 2" and 3" printers are similar except for the positions and sizes of the bar code and text fields.
You may use the LABEL_x member to include a label group to the printer settings object, where x is a number to make the member name unique. The next example shows two printer settings objects including 2in_FingerprintLabels and 3in_FingerprintLabels respectively. The application can specify "ItemLabel" or "URL_QRLabel" in the aFormat parameter of the LabelPrinter.writeLabel method regardless of the printer. If a LabelPrinter object was created for PB22_Fingerprint, the object prints the 2" label. If a LabelPrinter object was created for PB32_Fingerprint, the object prints the 3" label.
"PRINTERS":
{
"PB22_Fingerprint":
{
"DisplayName":"PB22 Bt Label Printer", "PrintHeadWidth": 384, "LABEL_01": "2in_FingerprintLabels",
"FormFeed": "[0x46,0x4F,0x52,0x4D,0x46,0x45,0x45,0x44]",
"Initialize": [], "NormalFont": [], "NullsBeforeClose": 0
},
"PB32_Fingerprint":
{
"DisplayName":"PB32 Bt Label Printer", "PrintHeadWidth": 576, "LABEL_01": "3in_FingerprintLabels",
"FormFeed": "[0x46,0x4F,0x52,0x4D,0x46,0x45,0x45,0x44]",
"Initialize": [], "NormalFont": [], "NullsBeforeClose": 0
}
}