Show / Hide Table of Contents

Export Labels to Image

Supported Output Image Formats

ThermalLabel SDK allows you to export/save the output label content to JPEG, PNG & PCX raster image formats and to SVG in vector format.

How Labels to Image Works?

The object in charge for the exportation is the PrintJob. Depending on the PrintJob settings, it is possible that after exportation, you get one file or multiple files.

To export a print job to an image file or stream you need to invoke the ExportToImage() method of the PrintJob object. You'll have 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).

Important

If you expect to print any label that was exported to PNG image format, then consider setting the ImageSettings's PngIncludeDpiMetadata property to True because by default, that value will not be saved into the output PNG image.

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 or multiple files.

  • If the scenario is Data Binding, Counters or Data Masking i.e. the PrintJob generates more than one ThermalLabel output, then you will get as many single image files as thermal label objects! Those files will be named with the name specified to ExportToImage() method indexed from 1 to N. If a Stream is specified, then that stream will contain a ZIP file containing each output label image and named with the DateTime Tick at the moment of creating such image.

  • If the PrintJob generates just one ThermalLabel output, then you will get only one image file in the specified format.

Generating Label Image Thumbnails

Generating label image thumbnails is supported through the ImageSettings class and if ImageFormat is PNG or JPEG and the ThumbnailSize property is set to a value greater than zero.

Labels to Image samples

  • Example #1: The following code will export a single ThermalLabel object to JPEG 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 image...
    pj.ExportToImage(tLabel, "c:\temp\myLabel.jpg", New ImageSettings(ImageFormat.Jpeg), 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 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 multiple JPEG files 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 image...
    pj.ExportToImage(tLabel, "c:\temp\myLabel.jpg", New ImageSettings(ImageFormat.Jpeg), 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 image...
    pj.ExportToImage(tLabel, @"c:\temp\myLabel.jpg", New ImageSettings(ImageFormat.Jpeg), 300);
}
Back to top Copyright © 2003- Neodynamic SRL
http://www.neodynamic.com