大多数热敏打印机不提供打印多列标签的媒体滚动内置机制。为了突破这个限制,ThermalLabel SDK提供的out-of-the-box属性可以让您打印任意数量的每一列标签!
本次教程中我们将会使用到的多列标签布局如下图所示:
详细步骤:
打开Visual Studio (v2005, or v2008, or 2010)并创建一个Windows窗体应用程序
添加一个引用到Neodynamic.SDK.ThermalLabel.dll集合
在窗体添加一个控制按钮,然后粘贴下列代码到该按钮的单击事件处理器中:
ZPL打印机
VB
'Define a ThermalLabel object and set unit to MM and label size
Dim tLabel As New ThermalLabel(UnitType.Mm, 50, 0)
'Set the number of labels per row
tLabel.LabelsPerRow = 2
'Set the horiz gap between labels
tLabel.LabelsHorizontalGapLength = 3
'Define a TextItem object
Dim txt As New TextItem(5, 5, "Decreasing 50")
'Set font...
txt.Font.CharHeight = 14
'set Counter...
txt.CounterStep = -1
'Define a BarcodeItem object
Dim bc As New BarcodeItem(5, 15, BarcodeSymbology.Code128, "ABC01")
'Set bars' width and height...
bc.BarWidth = 0.4
bc.BarHeight = 10
'set Counter...
bc.CounterStep = 1
bc.CounterUseLeadingZeros = True
'Add items to ThermalLabel object...
tLabel.Items.Add(txt)
tLabel.Items.Add(bc)
'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL
'Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra GK420t"
'Set Copies to 10!!!
pj.Copies = 10
'Print ThermalLabel object...
pj.Print(tLabel)
C#
//Define a ThermalLabel object and set unit to MM and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Mm, 50, 0);
//Set the number of labels per row
tLabel.LabelsPerRow = 2;
//Set the horiz gap between labels
tLabel.LabelsHorizontalGapLength = 3;
//Define a TextItem object
TextItem txt = new TextItem(5, 5, "Decreasing 50");
//Set font...
txt.Font.CharHeight = 14;
//set Counter...
txt.CounterStep = -1;
//Define a BarcodeItem object
BarcodeItem bc = new BarcodeItem(5, 15, BarcodeSymbology.Code128, "ABC01");
//Set bars' width and height...
bc.BarWidth = 0.4;
bc.BarHeight = 10;
//set Counter...
bc.CounterStep = 1;
bc.CounterUseLeadingZeros = true;
//Add items to ThermalLabel object...
tLabel.Items.Add(txt);
tLabel.Items.Add(bc);
//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.ZPL;
//Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra GK420t";
//Set Copies to 10!!!
pj.Copies = 10;
//Print ThermalLabel object...
pj.Print(tLabel);
EPL打印机
VB
'Define a ThermalLabel object and set unit to MM and label size
Dim tLabel As New ThermalLabel(UnitType.Mm, 50, 30)
'Set the number of labels per row
tLabel.LabelsPerRow = 2
'Set the horiz gap between labels
tLabel.LabelsHorizontalGapLength = 3
'Set the vertical gap between labels
tLabel.GapLength = 3
'Define a TextItem object
Dim txt As New TextItem(5, 5, "Decreasing 50")
'Set font...
txt.Font.Name = "2"
txt.Font.CharHeight = 14
txt.Font.CharWidth = 8
'set Counter...
txt.CounterStep = -1
'Define a BarcodeItem object
Dim bc As New BarcodeItem(5, 15, BarcodeSymbology.Code128, "ABC01")
'Set bars' width and height...
bc.BarWidth = 0.4
bc.BarHeight = 10
'set Counter...
bc.CounterStep = 1
bc.CounterUseLeadingZeros = True
'Add items to ThermalLabel object...
tLabel.Items.Add(txt)
tLabel.Items.Add(bc)
'Create a PrintJob object
Dim pj As New PrintJob()
'Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB
'Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203
'Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.EPL
'Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra GK420t"
'Set Copies to 10!!!
pj.Copies = 10
'Print ThermalLabel object...
pj.Print(tLabel)
C#
//Define a ThermalLabel object and set unit to MM and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Mm, 50, 0);
//Set the number of labels per row
tLabel.LabelsPerRow = 2;
//Set the horiz gap between labels
tLabel.LabelsHorizontalGapLength = 3;
//Set the vertical gap between labels
tLabel.GapLength = 3;
//Define a TextItem object
TextItem txt = new TextItem(5, 5, "Decreasing 50");
//Set font...
txt.Font.Name = "2";
txt.Font.CharHeight = 14;
txt.Font.CharWidth = 8;
//set Counter...
txt.CounterStep = -1;
//Define a BarcodeItem object
BarcodeItem bc = new BarcodeItem(5, 15, BarcodeSymbology.Code128, "ABC01");
//Set bars' width and height...
bc.BarWidth = 0.4;
bc.BarHeight = 10;
//set Counter...
bc.CounterStep = 1;
bc.CounterUseLeadingZeros = true;
//Add items to ThermalLabel object...
tLabel.Items.Add(txt);
tLabel.Items.Add(bc);
//Create a PrintJob object
PrintJob pj = new PrintJob();
//Thermal Printer is connected through USB
pj.PrinterSettings.Communication.CommunicationType = CommunicationType.USB;
//Set Thermal Printer resolution
pj.PrinterSettings.Dpi = 203;
//Set Thermal Printer language
pj.PrinterSettings.ProgrammingLanguage = ProgrammingLanguage.EPL;
//Set Thermal Printer name
pj.PrinterSettings.PrinterName = "Zebra GK420t";
//Set Copies to 10!!!
pj.Copies = 10;
//Print ThermalLabel object...
pj.Print(tLabel);
运行示例Windows窗体应用程序并测试,输出的打印效果如下图所示:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。