Export Labels to HTML
Export to HTML Overview
ThermalLabel SDK allows you to export/save the output label content to HTML document format.
The object in charge for the exportation is the PrintJob. The generated HTML document will contain one label or multiple labels depending on the PrintJob settings and scenario.
To export a print job to an HTML file or stream you need to invoke the ExportToHtml()
method of the PrintJob object. You'll need to specify the file or stream where to save the output content, an output resolution (DPI) value and the HTML Title if desired (if Title is empty, then the HTML markup will contain the BODY content only).
Labels to HTML samples
- Example #1: The following code will export a single ThermalLabel object to PDF format at 300dpi
VB
'Define a ThermalLabel object and set unit to inch and label size
Dim tLabel As New ThermalLabel(UnitType.Inch, 4, 3)
tLabel.GapLength = 0.2
'Define a TextItem object
Dim txtItem As New TextItem(0.2, 0.2, 1, 0.5, "Thermal Label Test")
'Define a BarcodeItem object
Dim bcItem As New BarcodeItem(0.2, 1, 2, 1, BarcodeSymbology.Code128, "ABC 12345")
'Set bars height to .75inch
bcItem.BarHeight = 0.75
'Set bars width to 0.0104inch
bcItem.BarWidth = 0.0104
'Add items to ThermalLabel object...
tLabel.Items.Add(txtItem)
tLabel.Items.Add(bcItem)
'Create a PrintJob object
Using pj As New PrintJob()
'Save output to HTML...
pj.ExportToHtml(tLabel, "c:\temp\myLabel.html", 300)
End Using
CS
//Define a ThermalLabel object and set unit to inch and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Inch, 4, 3);
tLabel.GapLength = 0.2;
//Define a TextItem object
TextItem txtItem = new TextItem(0.2, 0.2, 1, 0.5, "Thermal Label Test");
//Define a BarcodeItem object
BarcodeItem bcItem = new BarcodeItem(0.2, 1, 2, 1, BarcodeSymbology.Code128, "ABC 12345");
//Set bars height to .75inch
bcItem.BarHeight = 0.75;
//Set bars width to 0.0104inch
bcItem.BarWidth = 0.0104;
//Add items to ThermalLabel object...
tLabel.Items.Add(txtItem);
tLabel.Items.Add(bcItem);
//Create a PrintJob object
using (PrintJob pj = new PrintJob())
{
//Save output to HTML...
pj.ExportToHtml(tLabel, @"c:\temp\myLabel.html", 300);
}
- Example #2: The following code will export a ThermalLabel object using Counters to a HTML file containing labels at 300dpi
VB
'Define a ThermalLabel object and set unit to inch and label size
Dim tLabel As New ThermalLabel(UnitType.Inch, 4, 3)
tLabel.GapLength = 0.2
'Define a TextItem object
Dim txtItem As New TextItem(0.2, 0.2, 1, 0.5, "This is a Counter: 0")
'Set counter
txtItem.CounterStep = 1
'Define a BarcodeItem object
Dim bcItem As New BarcodeItem(0.2, 1, 2, 1, BarcodeSymbology.Code128, "ABC 12345")
'Set counter
bcItem.CounterStep = 1
'Set bars height to .75inch
bcItem.BarHeight = 0.75
'Set bars width to 0.0104inch
bcItem.BarWidth = 0.0104
'Add items to ThermalLabel object...
tLabel.Items.Add(txtItem)
tLabel.Items.Add(bcItem)
'Create a PrintJob object
Using pj As New PrintJob()
'Set number of copies
pj.Copies = 5
'Save output to HTML...
pj.ExportToHtml(tLabel, "c:\temp\myLabels.html", 300)
End Using
CS
//Define a ThermalLabel object and set unit to inch and label size
ThermalLabel tLabel = new ThermalLabel(UnitType.Inch, 4, 3);
tLabel.GapLength = 0.2;
//Define a TextItem object
TextItem txtItem = new TextItem(0.2, 0.2, 1, 0.5, "Thermal Label Test");
//Set counter
txtItem.CounterStep = 1;
//Define a BarcodeItem object
BarcodeItem bcItem = new BarcodeItem(0.2, 1, 2, 1, BarcodeSymbology.Code128, "ABC 12345");
//Set counter
bcItem.CounterStep = 1;
//Set bars height to .75inch
bcItem.BarHeight = 0.75;
//Set bars width to 0.0104inch
bcItem.BarWidth = 0.0104;
//Add items to ThermalLabel object...
tLabel.Items.Add(txtItem);
tLabel.Items.Add(bcItem);
//Create a PrintJob object
using (PrintJob pj = new PrintJob())
{
//Set number of copies
pj.Copies = 5;
//Save output to HTML...
pj.ExportToHtml(tLabel, @"c:\temp\myLabels.html", 300);
}