Print the ItemLabel defined in the Example Printer Commands and Attributes for Label Printing to a PB32 printer. The label uses the PB32_Fingerprint printer settings which include the 3in_FingerprintLabels label group. The label group is defined by ItemLabel as follows:
"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": "$$"
}
This label definition specifies a data stream in Fingerprint commands to print the label. See the Fingerprint Command Reference Manual (P/N 937-005-00x) for complete command information.
The next table explains the Fingerprint commands specified in the LabelDataStream setting.
Fingerprint Command | Description |
---|---|
DIR 4 | Specifies a direction to print the label. |
AN 7 | Specifies the anchor point. |
PP 40, 180 | Sets the insertion point to (40, 180). |
FT "Swiss 721 Bold Condensed BT",20 | Uses "Swiss 721 Bold Condensed BT" font with a height of 20 pts. |
PT "ItemName$$" | Provides input data for a text field. ItemName$$ specifies a variable name "ItemName" with a postfix of "$$". This variable is replaced by the "ItemName" key value in the aDictionary parameter passed to the LabelPrinter.writeLabel method. Note that ItemName$$ is not Fingerprint variable syntax. The double quotes around it are required for a text string. |
PP 150,180 | Sets the insertion point to (150, 180). |
BARSET "CODE128",3,1,4,240 | Specifies the Code 128 parameters. |
PB "ItemNo$$" | Provides input data for a bar code. ItemNo$$ specifies a variable name "ItemNo" with a postfix of "$$". This variable is replaced by the "ItemNo" key value in the dictionary parameter passed to this method. Note that ItemNo$$ is not Fingerprint variable syntax. The double quotes around it are required for a text string. |
PP 400, 330 | Sets the insertion point to (400, 330). |
FT "Letter Gothic 12 Pitch BT",14 | Uses "Letter Gothic 12 Pitch BT" font with a height of 14 pts. |
PT "ItemNoSS" | Provides input data for a text field. See the description of "ItemNo$$" for an explanation of the variable substitution. |
PF | Prints the label. |
The following code snippet prints the label:
import android.os.AsyncTask;
import android.app.Activity; import com.honeywell.mobility.print.*;
public class PrintActivity extends Activity
{
private void createPrintTask()
{
PrintTask task = new PrintTask();
// Executes PrintTask with the specified parameters which // will be passed to the PrintTask.doInBackground method.
// In this case, the doInBackground method does not expect
// any parameter.
task.execute();
}
class PrintTask extends AsyncTask<Void, Integer, Void>
{
@Override
protected Void doInBackground(Void... args)
{
doPrint();
return null;
}
private void doPrint()
{
LabelPrinter lp = null;
LabelPrinter.ExtraSettings exSettings =
new LabelPrinter.ExtraSettings();
exSettings.setContext(PrintActivity.this);
try
{
// Assumes the printer_profiles.JSON contains the
// contents of the LINEPRINTERCONTROL JSON object
// in the Example Printer Commands and Attributes
// for Label Printing section. It also assumes the
// file has been copied to the external storage.
File profiles = new File (getExternalFilesDir(null), "printer_profiles.JSON");
lp = new LabelPrinter(profiles.getAbsolutePath(),
"PB32_Fingerprint",
"bt://00:02:5B:CF:B3:20",
exSettings);
lp.connect(); // Connects to the printer
// Sets up the variable dictionary.
LabelPrinter.VarDictionary varDataDict =
new LabelPrinter.VarDictionary();
varDataDict.put("ItemName", "Honeywell AirGenius 4");
varDataDict.put("ItemNo", "92926003104");
// Prints the ItemLabel as defined in the
// printer_profiles.JSON file.
lp.writeLabel("ItemLabel", varDataDict);
// You may print more labels.
}
catch (LabelPrinterException ex)
{
// Handles LabelPrinter exceptions
}
catch (Exception ex)
{
// Handles other exceptions
}
finally
{
if (lp != null)
{
try
{
// Note: The PB32_Fingerprint printer settings
// specify a PreCloseDelay setting to ensure the
// label data stream is transmitted to the
// printer before the connection is closed.
lp.disconnect(); // Disconnects from the printer
lp.close(); // Releases resources
}
catch (Exception ex) {}
}
}
}
}
}
When the above lp.writeLabel method is executed, the following printer commands are sent to the printer after variable replacements:
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