Blue Bamboo P25 printer is a lightweight and portable thermal printer that provides low cost printing in mobile and wireless environments. It supports mobile application printing over Bluetooth, USB or Serial port (RS-232). It also has a good connectivity with Android device, makes printing from Android becomes very easy and fast.
Blue Bamboo also provides a sample Android project to show how to build an application that supports printing using P25 printer over Bluetooth. The source code itself is quite old so i made a slight modification with fresh UI and easy to read source code so developers can easily implement the codes into their projects.
This sample code shows how to print text, image, barcode and receipt into P25 printer using Bluetooth connectivity. The source code is available on Github repo, you can find it at the bottom of this post.
Print Text
private void printText(String text) { byte[] line = Printer.printfont(text + "\n\n", FontDefine.FONT_32PX, FontDefine.Align_CENTER, (byte) 0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] senddata = PocketPos.FramePack(PocketPos.FRAME_TOF_PRINT, line, 0, line.length); sendData(senddata); }
Use Printer.printFont(String content, byte fonttype, byte fontalign,byte linespace, byte language) method to format and position the text. For font types and text alignment, see FontDefine.java and for language definition, see PocketPos.java. Also call the PocketPos.FramePack(byte typeFrame, byte[] srcBuff, int srcOffset, int srcLen) to create frame data before sending to printer.
See P25 development guide page 60-63 for more information.
Print 1D Barcode
private void print1DBarcode() { String content = "6901234567892"; byte[] formats = {(byte) 0x1d, (byte) 0x6b, (byte) 0x02, (byte) 0x0d}; byte[] contents = content.getBytes(); byte[] bytes = new byte[formats.length + contents.length]; System.arraycopy(formats, 0, bytes, 0, formats.length); System.arraycopy(contents, 0, bytes, formats.length, contents.length); sendData(bytes); byte[] newline = Printer.printfont("\n\n",FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); sendData(newline); }
1D barcode printing format is: 1d 6b 02 0d [barcode data]. So to print “6901234567892” barcode data, the bytes would be:
{(byte) 0x1d, (byte) 0x6b, (byte) 0x02, (byte) 0x0d}
+
“6901234567892”.getBytes()
See P25 development guide page 59-60 for more information.
Print 2D Barcode
private void print2DBarcode() { String content = "Lorenz Blog - www.londatiga.net"; byte[] formats = {(byte) 0x1d, (byte) 0x6b, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1f}; byte[] contents = content.getBytes(); byte[] bytes = new byte[formats.length + contents.length]; System.arraycopy(formats, 0, bytes, 0, formats.length); System.arraycopy(contents, 0, bytes, formats.length, contents.length); sendData(bytes); byte[] newline = Printer.printfont("\n\n",FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); sendData(newline); }
2D barcode printing format is: 1d 6b 10 00 00 00 00 00 1f + barcode data. So to print “Lorenz Blog – www.londatiga.net” text, the bytes would be:
{(byte) 0x1d, (byte) 0x6b, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1f}
+
“Lorenz Blog – www.londatiga.net”.getBytes()
See P25 development guide page 60 for more information
Print Image
private void printImage() { try { byte[] formats = { (byte)0x1B, (byte)0x58, (byte)0x31, (byte)0x24, (byte)0x2D }; //bluebamboo logo byte[] image = {(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, ....... (byte)0x00}; sendData(bytes); byte[] newline = Printer.printfont("\n\n",FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); sendData(newline); } catch (Exception e) { e.printStackTrace(); } }
Image printing format is: 1B 58 31 xx yy + {image data in bitmap monochrome format} where xx is width in pixels/8 and yy is height of image in pixels.
So to print 200×45 pixels of image, the format would be :
{ (byte)0x1B, (byte)0x58, (byte)0x31, (byte)0x24, (byte)0x2D } + { bytes of bitmap monochrome image}
Width = 200pixels/8bit = 25 in decimals = 0x24 in hexa
Height= 45 pixels in decimal = 0x2D in hexa
See http://bluebamboo.helpserve.com/index.php?/Knowledgebase/Article/View/48 for more information on how to print image and P25 development guide page 18-13 and 63.
Print Sample Receipt
private void printStruk() { String titleStr = "STRUK PEMBAYARAN TAGIHAN LISTRIK" + "\n\n"; StringBuilder contentSb = new StringBuilder(); contentSb.append("IDPEL : 435353535435353" + "\n"); contentSb.append("NAMA : LORENSIUS WLT" + "\n"); contentSb.append("TRF/DAYA : 50/12244 VA" + "\n"); contentSb.append("BL/TH : 02/14" + "\n"); contentSb.append("ST/MTR : 0293232" + "\n"); contentSb.append("RP TAG : Rp. 100.000" + "\n"); contentSb.append("JPA REF :" + "\n"); StringBuilder content2Sb = new StringBuilder(); content2Sb.append("ADM BANK : Rp. 1.600" + "\n"); content2Sb.append("RP BAYAR : Rp. 101.600,00" + "\n"); String jpaRef = "XXXX-XXXX-XXXX-XXXX" + "\n"; String message = "PLN menyatakan struk ini sebagai bukti pembayaran yang sah." + "\n"; String message2 = "Rincian tagihan dapat diakses di www.pln.co.id Informasi Hubungi Call Center: " + "123 Atau Hub PLN Terdekat: 444" + "\n"; long milis = System.currentTimeMillis(); String date = DateUtil.timeMilisToString(milis, "dd-MM-yy / HH:mm") + "\n\n"; byte[] titleByte = Printer.printfont(titleStr, FontDefine.FONT_24PX,FontDefine.Align_CENTER, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] content1Byte = Printer.printfont(contentSb.toString(), FontDefine.FONT_24PX,FontDefine.Align_LEFT, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] refByte = Printer.printfont(jpaRef, FontDefine.FONT_24PX,FontDefine.Align_CENTER, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] messageByte = Printer.printfont(message, FontDefine.FONT_24PX,FontDefine.Align_CENTER, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] content2Byte = Printer.printfont(content2Sb.toString(), FontDefine.FONT_24PX,FontDefine.Align_LEFT, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] message2Byte = Printer.printfont(message2, FontDefine.FONT_24PX,FontDefine.Align_CENTER, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] dateByte = Printer.printfont(date, FontDefine.FONT_24PX,FontDefine.Align_LEFT, (byte)0x1A, PocketPos.LANGUAGE_ENGLISH); byte[] totalByte = new byte[titleByte.length + content1Byte.length + refByte.length + messageByte.length + content2Byte.length + message2Byte.length + dateByte.length]; int offset = 0; System.arraycopy(titleByte, 0, totalByte, offset, titleByte.length); offset += titleByte.length; System.arraycopy(content1Byte, 0, totalByte, offset, content1Byte.length); offset += content1Byte.length; System.arraycopy(refByte, 0, totalByte, offset, refByte.length); offset += refByte.length; System.arraycopy(messageByte, 0, totalByte, offset, messageByte.length); offset += messageByte.length; System.arraycopy(content2Byte, 0, totalByte, offset, content2Byte.length); offset += content2Byte.length; System.arraycopy(message2Byte, 0, totalByte, offset, message2Byte.length); offset += message2Byte.length; System.arraycopy(dateByte, 0, totalByte, offset, dateByte.length); byte[] senddata = PocketPos.FramePack(PocketPos.FRAME_TOF_PRINT, totalByte, 0, totalByte.length); sendData(senddata); }
Print Demo Page
private void printDemoContent(){ /*********** print head*******/ String receiptHead = "************************" + " P25/M Test Print"+"\n" + "************************" + "\n"; long milis = System.currentTimeMillis(); String date = DateUtil.timeMilisToString(milis, "MMM dd, yyyy"); String time = DateUtil.timeMilisToString(milis, "hh:mm a"); String hwDevice = Build.MANUFACTURER; String hwModel = Build.MODEL; String osVer = Build.VERSION.RELEASE; String sdkVer = String.valueOf(Build.VERSION.SDK_INT); StringBuffer receiptHeadBuffer = new StringBuffer(100); receiptHeadBuffer.append(receiptHead); receiptHeadBuffer.append(Util.nameLeftValueRightJustify(date, time, DataConstants.RECEIPT_WIDTH) + "\n"); receiptHeadBuffer.append(Util.nameLeftValueRightJustify("Device:", hwDevice, DataConstants.RECEIPT_WIDTH) + "\n"); receiptHeadBuffer.append(Util.nameLeftValueRightJustify("Model:", hwModel, DataConstants.RECEIPT_WIDTH) + "\n"); receiptHeadBuffer.append(Util.nameLeftValueRightJustify("OS ver:", osVer, DataConstants.RECEIPT_WIDTH) + "\n"); receiptHeadBuffer.append(Util.nameLeftValueRightJustify("SDK:", sdkVer, DataConstants.RECEIPT_WIDTH)); receiptHead = receiptHeadBuffer.toString(); byte[] header = Printer.printfont(receiptHead + "\n", FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); /*********** print English text*******/ StringBuffer sb = new StringBuffer(); for(int i=1; i<128; i++) sb.append((char)i); String content = sb.toString().trim(); byte[] englishchartext24 = Printer.printfont(content + "\n",FontDefine.FONT_24PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); byte[] englishchartext32 = Printer.printfont(content + "\n",FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); byte[] englishchartext24underline = Printer.printfont(content + "\n",FontDefine.FONT_24PX_UNDERLINE,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); //2D Bar Code byte[] barcode = StringUtil.hexStringToBytes("1d 6b 02 0d 36 39 30 31 32 33 34 35 36 37 38 39 32"); /*********** print Tail*******/ String receiptTail = "Test Completed" + "\n" + "************************" + "\n"; String receiptWeb = "** www.londatiga.net ** " + "\n\n\n"; byte[] foot = Printer.printfont(receiptTail,FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); byte[] web = Printer.printfont(receiptWeb,FontDefine.FONT_32PX,FontDefine.Align_CENTER,(byte)0x1A,PocketPos.LANGUAGE_ENGLISH); byte[] totladata = new byte[header.length + englishchartext24.length + englishchartext32.length + englishchartext24underline.length + + barcode.length + foot.length + web.length ]; int offset = 0; System.arraycopy(header, 0, totladata, offset, header.length); offset += header.length; System.arraycopy(englishchartext24, 0, totladata, offset, englishchartext24.length); offset+= englishchartext24.length; System.arraycopy(englishchartext32, 0, totladata, offset, englishchartext32.length); offset+=englishchartext32.length; System.arraycopy(englishchartext24underline, 0, totladata, offset, englishchartext24underline.length); offset+=englishchartext24underline.length; System.arraycopy(barcode, 0, totladata, offset, barcode.length); offset+=barcode.length; System.arraycopy(foot, 0, totladata, offset, foot.length); offset+=foot.length; System.arraycopy(web, 0, totladata, offset, web.length); offset+=web.length; byte[] senddata = PocketPos.FramePack(PocketPos.FRAME_TOF_PRINT, totladata, 0, totladata.length); sendData(senddata); }
All bytes data to be printed is sent to printer using sendData method from P25Connector class (P25Connector.java)
private void sendData(byte[] bytes) { try { mConnector.sendData(bytes); } catch (P25ConnectionException e) { e.printStackTrace(); } }
P25Connector is a wrapper class to handle bluetooth operation (connect, disconnect, and bluetooth socket operation)
Demo video
Real life application video
[ad#ad-720×90]
Download source code from Github repo







This is awesome! Is it possible to use it alongside a credit card reader application like square:
https://squareup.com/?priorityCode=3969702399&cid=aff_cj_6150547
Thanks! You’re awesome!
Slmt malam.Pak bisa tlg dibantu cara cek mac address nya. Printer sy Blue Bamboo P25. Pin nya 19734637. No serinya P25_062135_01. Sy sangat perlu sekali pak mac address. Sblm dan sesudahnya sy mengucapkan banyak terima kasih. Kl bisa di email saja pak ke : asharyunus2112@gmail.com.
Hi have gotten a hand of your tutorial. But can’t print any image I pass unto Method getBytesFromAssets in the FileOperation Class.
The picture is located within the assets folder and still doesn’t work.
please send me demo for Map view inside scroll view & Print recipients for printer for
android
Great one Loresius,
From the source code when i printtext, reciept, barcode, or demo there extra strings printed before the actual print, do you know how they can be removed. eg printext > string (“Test”) will Print 1D456Test instead of just Test
tutorialnya bagus mas, oh iya, saya untuk ngeprint image dengan contoh gambar sendiri dengan extensi bitmap monochrome dengan ukuruan seperti yang dijelaskan diatas, tapi masih hancur ya kira2 sebabnya apa yak..? trimakasih
shows the p200 blue bamboo tutorial, please
Om Boleh di kirimin sorce code lenkap nggak ?? Buat Tugas nih ,,, Izin untuk di ATM dong kalau boleh rofidhilmi59@gmail.com. Terimakasih
Hi
Do you have library to convert jpg image to image data in bitmap monochrome format?
Thanks
Hello,
Sebelumnya saya ucapkan terkma kasih atas artkel blognya mengenai printer bluebamboo yg sdh diupload di github. Yang ingin saya tanyakan, apakah memungkinkan sdk tersebut digunakan untuk PHP web base system ?
Kasusnya begini: di tempat tersbut sudah memilikki aplikasi php web base , jadi rencananya, aplikasi web base tersebut mau dibuka di tablet dan kemudian print menggunskan portable pos bluebamboo. Apakah memungkinkan ?
Terima kasih sebelumnya
540919
hi i want to develop a app which use zebra imz 320 pinter with bluetooth on android. your project(p25demo) is very helpfull for me. how can i set paper size? can u help me?
thanks for the tutorial. In your image printing, you said the image is 200px wide, but 0x24 is not 25 pixels (rather 36 px). I think you want 0x19.
Great post! It’s helping me a lot. Just bought BlueBamboo P10 bluetooth printer and thanks to this post I am able to print!
Now Dear Lorensius, how do you generate that hex string of the monochrome image?
Last, I printed the image once and on subsquent printing wierd string are being printed out instead of the image.
I’d appreciate your help on the above.
Thanks in advance.
Innocent
I have the printer but need to download the software on my phone. Is there a link to a download? I changed phones and need to download again. I use a square but use to use intuit as a merchant account. please advise.
need the software to download. I have the printer. changed form iphone to android. used intuit and now using square.
hi is possible to use asyn task to connect the background and print on posExecute ?
Which directory should I put these files I downloaded the Github
Hi, Your demo look cool, but have question that is this only for “Blue Bamboo P25 printer” other printer will also work or not because I am not able to get the list of Bluetooth devices.
Can you please help me.
I am not able to connect to other bluetooth device from android phone.
Android Demo Application With Source Code Blue Bamboo P25 Printer Android Demo Application With Source Code.
Can i get this demo code for Android studio ?
Android Demo Application With Source Code
Blue Bamboo P25 Printer Android Demo Application With Source Code.
am trying with android studio. Can i get the code for that ?