I try to print labels to my bluetooth thermal printer from an android app. I manage to print text but I can't specify the size of my labels
My material:
- bluetooth thermal printer : here
- 4"x2" labels = 100mmx50mm
- apps: FlashLabel PrintLabel
My printer can detect the labels. For example, when I load paper, it automatically aligns to print on the first label. With the FlashLabel or PrintLabel app, once the text is printed, the printer outputs the label. I can't do this: my text prints correctly but the label only comes out halfway. It seems to me that the printer uses the TSPL communication protocol. Is it this ? If you want, I decompiled the 2 apps that work to try to see how it's done but without success
Here, where I am actually :
private class PrintTask extends AsyncTask<BluetoothDevice, Void, Void> {
@Override
protected Void doInBackground(BluetoothDevice... devices) {
BluetoothDevice printerDevice = devices[0];
try {
// Establish Bluetooth connection with the printer
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); // UUID for SPP (Serial Port Profile)
bluetoothSocket = printerDevice.createRfcommSocketToServiceRecord(uuid);
bluetoothSocket.connect();
// Get the output stream to send print data
outputStream = bluetoothSocket.getOutputStream();
// Send TSPL commands to set up the label (102mm x 51mm) and print "Hello World" with larger font size
String printData = "SIZE 100 mm,50 mm\nGAP 0 mm,0 mm\nCLS\nTEXT 10 mm,10 mm,\"0\",0,2,2,\"Hello World\"\nPRINT 1,1\n";
// Add escape command
printData += "HOME\n";
printData += "PRINT 1,1\n";
outputStream.write(printData.getBytes());
// Close the Bluetooth connection and output stream
outputStream.close();
bluetoothSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
// Display a successful print message
Toast.makeText(MainActivity.this, "Printok", Toast.LENGTH_SHORT).show();
}
}
Thanks in advance to anyone who will take the time to help me.