Printing
This is the good part. Let's put ink on paper.
Before You Print
Two things need to happen before you can print:
- You're connected to a device (Getting Started)
- Your templates and fonts are uploaded to the device (Resource Management)
Your First Print
import com.averydennison.addevicemanager.adapters.PrinterAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Logger logger = LoggerFactory.getLogger(getClass());
// Get the printer adapter from your connected device
PrinterAdapter printerAdapter = deviceAdapter.getPrinterAdapter();
// Print one label using a template
printerAdapter.print("PriceTag.ngt", "PRICE=9.99", 1)
.thenAccept(unused -> {
logger.info("Label printed!");
})
.exceptionally(error -> {
logger.error("Print failed: {}", error.getMessage());
return null;
});
That's it. Three parameters:
| Parameter | Description |
|---|---|
| Template name | The .ngt file you uploaded |
| Data | Values to fill into the template |
| Copies | How many labels to print |
Templates and Variables
Templates are label designs with placeholder variables. You define the layout once, then fill in different data each time you print.
Variable Syntax
Variables use curly braces: {VARIABLE_NAME}
When printing, pass values as KEY=VALUE pairs separated by semicolons:
// Template has {PRODUCT} and {PRICE} placeholders
String data = "PRODUCT=Organic Coffee;PRICE=12.99";
printerAdapter.print("RetailLabel.ngt", data, 1);
Template File Formats
| Device | Extension | Language |
|---|---|---|
| Pathfinder Edge | .ngt | TSPL |
| Pathfinder 6059/6140 | .lnt | XML |
TSPL Basics
TSPL (TSC Printer Language) is a text-based command language used to control label and barcode printers. You send these commands directly to the printer to define the layout and content of your labels.
Label Setup Commands
SIZE 2,1 ; Label is 2 inches wide, 1 inch tall (mm if specified)
CLS ; Clear the buffer (always do this first)
DIRECTION 1,0 ; Print orientation
SIZE units:
- Default is inches:
SIZE 2,1= 2" × 1" - Specify mm:
SIZE 50 mm,25 mm
DIRECTION values:
- First number:
0= upside down,1= upright - Second number:
0= normal,1= mirror image
Adding Text
TEXT 20,30,"Roboto-Bold.TTF",0,12,12,"Hello World"
; │ │ │ │ │ │ └── Your text (or variable)
; │ │ │ │ │ └── Y scale multiplier
; │ │ │ │ └── X scale multiplier
; │ │ │ └── Rotation (0, 90, 180, 270)
; │ │ └── Font file (must be uploaded to device)
; │ └── Y position (dots from top)
; └── X position (dots from left)
Adding Barcodes
BARCODE 100,50,"128",80,1,0,2,4,"1234567890"
; │ │ │ │ │ │ │ │ └── Data to encode
; │ │ │ │ │ │ │ └── Wide bar width
; │ │ │ │ │ │ └── Narrow bar width
; │ │ │ │ │ └── Rotation (0, 90, 180, 270)
; │ │ │ │ └── Show human-readable text (0=no, 1=yes, 2=below)
; │ │ │ └── Height in dots
; │ │ └── Barcode type ("128", "EAN13", "39", etc.)
; │ └── Y position
; └── X position
Common barcode types:
"128"— Code 128 (alphanumeric)"EAN13"— EAN-13 (retail)"39"— Code 39 (alphanumeric)"UPCA"— UPC-A (retail)
Print Command
PRINT 1,1 ; Print 1 set of 1 copy
PRINT 1 ; Print 1 copy
Note: An empty line at the end of the template is required to signal the end of the TSPL commands. The print command along with the new line is appended by the SDK; so your template should not include a PRINT command or a new line at the end. The SDK will handle that for you when you call printerAdapter.print().
Example Templates
Simple Price Tag
SIZE 2,1
CLS
DIRECTION 1,0
TEXT 20,20,"Roboto-Bold.TTF",0,14,14,"{PRODUCT}"
TEXT 20,60,"Roboto-Regular.TTF",0,10,10,"${PRICE}"
Usage:
printerAdapter.print("PriceTag.ngt", "PRODUCT=Coffee Beans;PRICE=12.99", 1);
Result:
┌─────────────────────────┐
│ Coffee Beans │
│ $12.99 │
└─────────────────────────┘
Barcode Label
SIZE 2,1
CLS
DIRECTION 1,0
TEXT 20,5,"Roboto-Regular.TTF",0,10,10,"{DESCRIPTION}"
BARCODE 20,40,"128",50,1,0,2,4,"{SKU}"
Usage:
printerAdapter.print("SkuLabel.ngt", "DESCRIPTION=Widget A;SKU=1234567890", 1);
Result:
┌─────────────────────────┐
│ Widget A │
│ ║│║║│║║│║║│║║│║║║│║ │
│ 1234567890 │
└─────────────────────────┘
Markdown Price (Was/Now)
SIZE 2,1
CLS
DIRECTION 1,0
TEXT 90,20,"Roboto-Bold.TTF",0,12,12,"Was: "
TEXT 178,20,"Roboto-Bold.TTF",0,12,12,"${ORIGINAL}"
TEXT 90,75,"Roboto-Bold.TTF",0,12,12,"Now: "
TEXT 178,70,"Roboto-Bold.TTF",0,16,16,"${SALE}"
Usage:
printerAdapter.print("SaleTag.ngt", "ORIGINAL=29.99;SALE=19.99", 1);
Multiple Barcodes and Text Fields
SIZE 2,2
CLS
BARCODE 190,30,"39",85,0,0,2,6,2,"{VAR1}"
BARCODE 190,230,"EAN13",85,0,0,2,2,2,"{VAR2}"
TEXT 55,145,"Roboto-Regular.TTF",0,0,10,"{VAR3}"
TEXT 130,175,"Roboto-Regular.TTF",0,0,10,"{VAR4}"
TEXT 10,185,"Roboto-Regular.TTF",0,0,6,"PF EDGE"
TEXT 350,185,"Roboto-Regular.TTF",0,0,6,"{VAR5}"
TEXT 10,300,"Roboto-Regular.TTF",0,0,6,"***********"
TEXT 300,300,"Roboto-Regular.TTF",0,0,6,"#########"
Printing Multiple Copies
The third parameter controls how many labels to print:
// Print 5 copies of the same label
printerAdapter.print("ShelfTag.ngt", "PRICE=4.99", 5);
To track progress of multi-copy jobs, see Callbacks.
Troubleshooting
| Problem | Solution |
|---|---|
| "Template not found" error | Upload the template first (see Resource Management). Check filename matches exactly (case-sensitive). |
| Label prints but looks wrong | Verify template's SIZE matches your physical label stock. Try flipping DIRECTION between 0 and 1. |
| Barcode won't scan after printing | Increase barcode height. Try wider bar widths. Ensure print head is clean. |
| Print job sent but nothing happens | Check printer status with PrinterStatusCallback. Is paper loaded? Is cover closed? |
| Text is cut off | Reduce font size or X/Y multipliers. Check text position fits within label SIZE. |
| Font not found | Ensure font file is uploaded to device with same filename used in template. |
Next Steps
| Guide | What You'll Learn |
|---|---|
| Scanning | Scan barcodes to drive print jobs |
| Resource Management | Upload and manage templates |
| Callbacks | Track print progress |
| Logging | Debug print issues |