Neodynamic ThermalLabel SDK for .NET
Export Labels to Image

In this section

Supported Output Image Formats
ThermalLabel SDK allows you to export/save the output label content to most popular raster image formats. The supported image formats are BMP (Bitmap), GIF (Graphics Interchange Format), JPEG (Joint Photographic Experts Group), PNG (Portable Network Graphics), and TIFF (Tagged Image File Format) including multi-page TIFF file.

How Labels to Image Works?
The object in charge for the exportation is the PrintJob. That means if you want to export a ThermalLabel object to some image file (or Stream), then you will need to do that by using a PrintJob object. Depending on the PrintJob settings, it is possible that after exportation, you get one file, multiple files or a multipage image file (only if TIFF format is selected).

To export a print job to an image file or stream you need to invoke the ExportToImage() method of the PrintJob object. That method asks you to specify the file or stream where to save the output content, the out image format by using an ImageSettings object, and an output resolution (DPI).

READ THIS CAREFULLY

Depending on the PrintJob & ThermalLabel scenario (Data Binding, Counters, Data Masking, Simgle Label, etc.) and the selected output Image Format, it is possible you get one file, multiple files or a multi-page image file.
  • If the scenario is Data Binding, Counters or Data Masking i.e. the PrintJob generates more than one ThermalLabel output, then you will get the following:
    • If you selected TIFF image format, you'll get One multi-page TIFF file .
    • If you selected BMP, GIF, PNG, or JPEG image formats, you'll get single image files As Many As thermal label objects. Those files will be named with the name specified to ExportToImage() method indexed from 1 to N.
  • If the PrintJob generates just one ThermalLabel output, then you will get One only image file in the specified format.


Labels to Image samples
Example #1: The following code will export a single ThermalLabel object to JPEG format at 300dpi


Visual Basic

'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 image...
	pj.ExportToImage(tLabel, "c:\temp\myLabel.jpg", New ImageSettings(ImageFormat.Jpeg), 300)
End Using


C#

//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 image...
	pj.ExportToImage(tLabel, @"c:\temp\myLabel.jpg", new ImageSettings(ImageFormat.Jpeg), 300);
}


Example #2: The following code will export a ThermalLabel object using Counters to a Multi-page TIFF file at 300dpi


Visual Basic

'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 image...
	pj.ExportToImage(tLabel, "c:\temp\myLabels.tif", New ImageSettings(ImageFormat.Tiff), 300)
End Using


C#

//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 image...
	pj.ExportToImage(tLabel, @"c:\temp\myLabels.tif", new ImageSettings(ImageFormat.Tiff), 300);
}