Use this class to print labels on a printer using a label language.
System.Object
Honeywell.AIDC.CrossPlatform.Print.Printer
Honeywell.AIDC.CrossPlatform.Print.LabelPrinter
public sealed class LabelPrinter : Printer;
The methods of this class must be called from a separate thread to not block the UI thread during lengthy printing operations. To print a label, the printer settings need to include the label definition. For more information, please refer to the Label Printing Commands and Attributes section of the Printer Commands and Attributes User Guide. This SDK provides a printer_profiles.JSON file with printer settings and example label definitions for PB22 and PB32 printers.
The following is an example LINEPRINTERCONTROL JSON object that defines a printer “PB32_Fingerprint” which includes a label definition group called “3in_FingerprintLabels.” The 3in_FingerprintLabels label group contains a label definition called “ItemLabel.”
{ "LINEPRINTERCONTROL": { "FormatVersion": "1.0.0.0", "DEFAULTS": { "NullsBeforeClose": 0, "PreCloseDelay": 0, "BtConnectRetries" : 3, "BtconnectRetryDelay" : 100, "BtWriteDataReadyTimeout" : 10000, "BtWriteIntervalTimeout" : 10000, "BtMaxSegWrite" : 1024, "BtLinger" : 10 }, "PRINTERS": { "PB32_Fingerprint": { "DisplayName":"PB32 Bt Label Printer", "LABEL_01": "3in_FingerprintLabels", "FormFeed": "[0x46,0x4F,0x52,0x4D,0x46,0x45,0x45,0x44]", "Initialize": [], "NormalFont": [], "NullsBeforeClose": 0, "PreCloseDelay": 1000 } }, "LABELS": { "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": "$$" } } } } }
The following is the sample code snippet that demonstrates calling the LabelPrinter API to print the ItemLabel defined in the above LINEPRINTERCONTROL JSON object. The profiles parameter contains the JSON string.
public async Task<String> DoPrint(string profiles) { string ret = await Task<string>.Run(() => { string result = string.Empty; LabelPrinter labelPrinter = null; Dictionary<string, string> varItemDictionary = new Dictionary<string, string>(); try { // Open printer connection labelPrinter = new LabelPrinter(profiles, "PB32_Fingerprint", "bt://00:02:5B:CF:B3:20"); labelPrinter.Connect(); // Sets up the variable dictionary. // "ItemName$$" in the label definition will be replaced with // "Honeywell AirGenius 4". varItemDictionary.Add("ItemName", "Honeywell AirGenius 4"); // "ItemNo$$" in the label definition will be replaced with // "92926003104". varItemDictionary.Add("ItemNo", "92926003104"); labelPrinter.WriteLabel("ItemLabel", varItemDictionary); result = "Done printing."; } catch (Exception ex) { result = "DoPrint exception: " + ex.Message; } finally { if (null != labelPrinter) { labelPrinter.Disconnect(); labelPrinter.Dispose(); } } return result; }); return ret; }
When the WriteLabel method is called, the following data is sent to the printer.
DIR 4 AN 7 PP 40, 180 FT "Swiss 721 Bold Condensed BT",20 PT "Honeywell AirGenius 4" PP 150,180 BARSET "CODE128",3,1,4,240 PB "92926003104" PP 400, 330 FT "Letter Gothic 12 Pitch BT",14 PT "92926003104" PF