Reputation: 4140
I have to print invoice receipt using thermal printer. I have used Zjiang Thermal printer to print receipt. They also provide there manual & demo project. In demo project they use a libray "btsdk.jar" to implement connection & print.
I have successfully establish connection between printer & android device. But there is no guideline for text alignment (center, left, right) & cell width, height.
I have try it. It only change text height by changing format2 variable.
How I print invoice by bluetooth printer.
please also explain this section-
byte[] cmd = new byte[3];
cmd[0] = 0x1b;
cmd[1] = 0x21;
cmd[2] |= 0x10;
cmd2 - used for change font height what is use of cmd[0] & cmd1
code to send Printing message to bluetooth Printer In Demo Project
String msg = "";
byte[] cmd = new byte[3];
cmd[0] = 0x1b;
cmd[1] = 0x21;
cmd[2] |= 0x10;
mService.write(cmd);
mService.sendMessage("Congratulations!\n", "GBK");
cmd[2] &= 0xEF;
mService.write(cmd);
msg = " You have sucessfully created communications between your device and our bluetooth printer.\n\n"
+" the company is a high-tech enterprise which specializes" +
" in R&D,manufacturing,marketing of thermal printers and barcode scanners.\n\n";
mService.sendMessage(msg,"GBK");
Print Info-
parameters:support to download the Logo trademark
FontA:12*24 dots,1.5(W)*3.0(H) mm
FontB:9*17 dots, 1.1(W)*2.1(H) mm
Simplified/Traditional: 24*24 dots, 3.0(W)*3.0(H)
Line spacing: 3.75mm (Default)
Barcode Types:-
1D Barcode- UPC-A/UPC-E, JAN13(EAN13), JAN8(EAN8), CODE39/ITF, CODABAR,CODE93
2d Barcode- QR CODE
Invoice Receipt
Upvotes: 15
Views: 20054
Reputation: 595
you can use this
void printLine(String txt, char type){
byte[] format = { 27, 33, 0 };
byte[] arrayOfByte1 = { 27, 33, 0 };
if (type == 'b') {
format[2] = ((byte) (0x8 | arrayOfByte1[2])); //BOLD
}
if (type == 'h') {
format[2] = ((byte) (0x10 | arrayOfByte1[2])); //HEIGHT
}
if (type == 'w') {
format[2] = ((byte) (0x20 | arrayOfByte1[2])); //WIDTH
}
if (type == 'u') {
format[2] = ((byte) (0x80 | arrayOfByte1[2])); //UNDERLINE
}
if (type == 's') {
format[2] = ((byte) (0x1 | arrayOfByte1[2])); //SMALL
}
mService.write(format);
mService.sendMessage(txt,"GBK");
}
credit goes to Leonardo Sapuy and his original q/a Format text in bluetooth printer and thanks to Murtaza Khursheed Hussain for sending me to it
Upvotes: 1
Reputation: 15336
I have found the following image over the internet for Text Alignment. Hope it helps
Upvotes: 7