1- [ ![ Jitpack package repository - ESCPOS-ThermalPrinter-Android v3.1.2 ] ( https://jitpack.io/v/DantSu/ESCPOS-ThermalPrinter-Android.svg )] ( https://jitpack.io/#DantSu/ESCPOS-ThermalPrinter-Android/3.1.2 )
1+ [ ![ Jitpack package repository - ESCPOS-ThermalPrinter-Android v3.2.0 ] ( https://jitpack.io/v/DantSu/ESCPOS-ThermalPrinter-Android.svg )] ( https://jitpack.io/#DantSu/ESCPOS-ThermalPrinter-Android/3.2.0 )
22[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
33
44# Android library for ESC/POS Thermal Printer
@@ -60,7 +60,7 @@ To test this library, it's pretty simple !
6060
6161## Installation
6262
63- ** Step 1.** Add the [ JitPack] ( https://jitpack.io/#DantSu/ESCPOS-ThermalPrinter-Android/3.1.2 ) repository to your build file. Add it in your root ` /build.gradle ` at the end of repositories:
63+ ** Step 1.** Add the [ JitPack] ( https://jitpack.io/#DantSu/ESCPOS-ThermalPrinter-Android/3.2.0 ) repository to your build file. Add it in your root ` /build.gradle ` at the end of repositories:
6464
6565```
6666allprojects {
@@ -76,7 +76,7 @@ allprojects {
7676```
7777dependencies {
7878 ...
79- implementation 'com.github.DantSu:ESCPOS-ThermalPrinter-Android:3.1.2 '
79+ implementation 'com.github.DantSu:ESCPOS-ThermalPrinter-Android:3.2.0 '
8080}
8181```
8282
@@ -90,16 +90,16 @@ Also, you have to check the bluetooth permission in your app like this :
9090
9191``` java
9292if (ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH ) != PackageManager . PERMISSION_GRANTED ) {
93- ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH }, MainActivity . PERMISSION_BLUETOOTH );
94- } else if (ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH_ADMIN ) != PackageManager . PERMISSION_GRANTED ) {
95- ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH_ADMIN }, MainActivity . PERMISSION_BLUETOOTH_ADMIN );
96- } else if (android.os. Build . VERSION. SDK_INT >= android.os. Build . VERSION_CODES. S && ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH_CONNECT ) != PackageManager . PERMISSION_GRANTED ) {
97- ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH_CONNECT }, MainActivity . PERMISSION_BLUETOOTH_CONNECT );
98- } else if (android.os. Build . VERSION. SDK_INT >= android.os. Build . VERSION_CODES. S && ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH_SCAN ) != PackageManager . PERMISSION_GRANTED ) {
99- ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH_SCAN }, MainActivity . PERMISSION_BLUETOOTH_SCAN );
100- } else {
101- // Your code HERE
102- }
93+ ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH }, MainActivity . PERMISSION_BLUETOOTH );
94+ } else if (ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH_ADMIN ) != PackageManager . PERMISSION_GRANTED ) {
95+ ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH_ADMIN }, MainActivity . PERMISSION_BLUETOOTH_ADMIN );
96+ } else if (android.os. Build . VERSION. SDK_INT >= android.os. Build . VERSION_CODES. S && ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH_CONNECT ) != PackageManager . PERMISSION_GRANTED ) {
97+ ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH_CONNECT }, MainActivity . PERMISSION_BLUETOOTH_CONNECT );
98+ } else if (android.os. Build . VERSION. SDK_INT >= android.os. Build . VERSION_CODES. S && ContextCompat . checkSelfPermission(this , Manifest . permission. BLUETOOTH_SCAN ) != PackageManager . PERMISSION_GRANTED ) {
99+ ActivityCompat . requestPermissions(this , new String []{Manifest . permission. BLUETOOTH_SCAN }, MainActivity . PERMISSION_BLUETOOTH_SCAN );
100+ } else {
101+ // Your code HERE
102+ }
103103```
104104
105105### Bluetooth code example
@@ -108,8 +108,8 @@ The code below is an example to write in your activity :
108108
109109``` java
110110EscPosPrinter printer = new EscPosPrinter (BluetoothPrintersConnections . selectFirstPaired(), 203 , 48f , 32 );
111- printer
112- .printFormattedText(
111+ printer
112+ .printFormattedText(
113113 " [C]<img>" + PrinterTextParserImg . bitmapToHexadecimalString(printer, this . getApplicationContext(). getResources(). getDrawableForDensity(R . drawable. logo, DisplayMetrics . DENSITY_MEDIUM ))+ " </img>\n " +
114114 " [L]\n " +
115115 " [C]<u><font size='big'>ORDER N°045</font></u>\n " +
@@ -136,7 +136,7 @@ printer
136136 " [L]\n " +
137137 " [C]<barcode type='ean13' height='10'>831254784551</barcode>\n " +
138138 " [C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>"
139- );
139+ );
140140```
141141
142142Below a picture of the receipt printed with the code above :
@@ -155,43 +155,43 @@ The code below is an example to write in your activity :
155155
156156``` java
157157new Thread (new Runnable () {
158- public void run () {
158+ public void run () {
159159 try {
160- EscPosPrinter printer = new EscPosPrinter (new TcpConnection (" 192.168.1.3" , 9300 , 15 ), 203 , 48f , 32 );
161- printer
162- .printFormattedText(
163- " [C]<img>" + PrinterTextParserImg . bitmapToHexadecimalString(printer, getApplicationContext(). getResources(). getDrawableForDensity(R . drawable. logo, DisplayMetrics . DENSITY_MEDIUM )) + " </img>\n " +
164- " [L]\n " +
165- " [C]<u><font size='big'>ORDER N°045</font></u>\n " +
166- " [L]\n " +
167- " [C]================================\n " +
168- " [L]\n " +
169- " [L]<b>BEAUTIFUL SHIRT</b>[R]9.99e\n " +
170- " [L] + Size : S\n " +
171- " [L]\n " +
172- " [L]<b>AWESOME HAT</b>[R]24.99e\n " +
173- " [L] + Size : 57/58\n " +
174- " [L]\n " +
175- " [C]--------------------------------\n " +
176- " [R]TOTAL PRICE :[R]34.98e\n " +
177- " [R]TAX :[R]4.23e\n " +
178- " [L]\n " +
179- " [C]================================\n " +
180- " [L]\n " +
181- " [L]<font size='tall'>Customer :</font>\n " +
182- " [L]Raymond DUPONT\n " +
183- " [L]5 rue des girafes\n " +
184- " [L]31547 PERPETES\n " +
185- " [L]Tel : +33801201456\n " +
186- " [L]\n " +
187- " [C]<barcode type='ean13' height='10'>831254784551</barcode>\n " +
188- " [C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>"
189- );
160+ EscPosPrinter printer = new EscPosPrinter (new TcpConnection (" 192.168.1.3" , 9300 , 15 ), 203 , 48f , 32 );
161+ printer
162+ .printFormattedText(
163+ " [C]<img>" + PrinterTextParserImg . bitmapToHexadecimalString(printer, getApplicationContext(). getResources(). getDrawableForDensity(R . drawable. logo, DisplayMetrics . DENSITY_MEDIUM )) + " </img>\n " +
164+ " [L]\n " +
165+ " [C]<u><font size='big'>ORDER N°045</font></u>\n " +
166+ " [L]\n " +
167+ " [C]================================\n " +
168+ " [L]\n " +
169+ " [L]<b>BEAUTIFUL SHIRT</b>[R]9.99e\n " +
170+ " [L] + Size : S\n " +
171+ " [L]\n " +
172+ " [L]<b>AWESOME HAT</b>[R]24.99e\n " +
173+ " [L] + Size : 57/58\n " +
174+ " [L]\n " +
175+ " [C]--------------------------------\n " +
176+ " [R]TOTAL PRICE :[R]34.98e\n " +
177+ " [R]TAX :[R]4.23e\n " +
178+ " [L]\n " +
179+ " [C]================================\n " +
180+ " [L]\n " +
181+ " [L]<font size='tall'>Customer :</font>\n " +
182+ " [L]Raymond DUPONT\n " +
183+ " [L]5 rue des girafes\n " +
184+ " [L]31547 PERPETES\n " +
185+ " [L]Tel : +33801201456\n " +
186+ " [L]\n " +
187+ " [C]<barcode type='ean13' height='10'>831254784551</barcode>\n " +
188+ " [C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>"
189+ );
190190 } catch (Exception e) {
191- e. printStackTrace();
191+ e. printStackTrace();
192192 }
193- }
194- }). start();
193+ }
194+ }). start();
195195```
196196
197197## USB
@@ -205,37 +205,37 @@ You have to check the USB permission in your app like this :
205205``` java
206206private static final String ACTION_USB_PERMISSION = " com.android.example.USB_PERMISSION" ;
207207private final BroadcastReceiver usbReceiver = new BroadcastReceiver () {
208- public void onReceive (Context context , Intent intent ) {
208+ public void onReceive (Context context , Intent intent ) {
209209 String action = intent. getAction();
210210 if (MainActivity . ACTION_USB_PERMISSION. equals(action)) {
211- synchronized (this ) {
212- UsbManager usbManager = (UsbManager ) getSystemService(Context . USB_SERVICE );
213- UsbDevice usbDevice = (UsbDevice ) intent. getParcelableExtra(UsbManager . EXTRA_DEVICE );
214- if (intent. getBooleanExtra(UsbManager . EXTRA_PERMISSION_GRANTED , false )) {
215- if (usbManager != null && usbDevice != null ) {
216- // YOUR PRINT CODE HERE
217- }
218- }
219- }
211+ synchronized (this ) {
212+ UsbManager usbManager = (UsbManager ) getSystemService(Context . USB_SERVICE );
213+ UsbDevice usbDevice = (UsbDevice ) intent. getParcelableExtra(UsbManager . EXTRA_DEVICE );
214+ if (intent. getBooleanExtra(UsbManager . EXTRA_PERMISSION_GRANTED , false )) {
215+ if (usbManager != null && usbDevice != null ) {
216+ // YOUR PRINT CODE HERE
220217 }
221- }
222- };
218+ }
219+ }
220+ }
221+ }
222+ };
223223
224224public void printUsb() {
225- UsbConnection usbConnection = UsbPrintersConnections . selectFirstConnected(this );
226- UsbManager usbManager = (UsbManager ) this . getSystemService(Context . USB_SERVICE );
227- if (usbConnection != null && usbManager != null ) {
225+ UsbConnection usbConnection = UsbPrintersConnections . selectFirstConnected(this );
226+ UsbManager usbManager = (UsbManager ) this . getSystemService(Context . USB_SERVICE );
227+ if (usbConnection != null && usbManager != null ) {
228228 PendingIntent permissionIntent = PendingIntent . getBroadcast(
229- this ,
230- 0 ,
231- new Intent (MainActivity . ACTION_USB_PERMISSION ),
232- android.os. Build . VERSION. SDK_INT >= android.os. Build . VERSION_CODES. S ? PendingIntent . FLAG_MUTABLE : 0
229+ this ,
230+ 0 ,
231+ new Intent (MainActivity . ACTION_USB_PERMISSION ),
232+ android.os. Build . VERSION. SDK_INT >= android.os. Build . VERSION_CODES. S ? PendingIntent . FLAG_MUTABLE : 0
233233 );
234234 IntentFilter filter = new IntentFilter (MainActivity . ACTION_USB_PERMISSION );
235235 registerReceiver(this . usbReceiver, filter);
236236 usbManager. requestPermission(usbConnection. getDevice(), permissionIntent);
237- }
238- }
237+ }
238+ }
239239```
240240
241241### USB code example
@@ -244,8 +244,8 @@ The code below is an example to write in your activity :
244244
245245``` java
246246EscPosPrinter printer = new EscPosPrinter (new UsbConnection (usbManager, usbDevice), 203 , 48f , 32 );
247- printer
248- .printFormattedText(
247+ printer
248+ .printFormattedText(
249249 " [C]<img>" + PrinterTextParserImg . bitmapToHexadecimalString(printer, this . getApplicationContext(). getResources(). getDrawableForDensity(R . drawable. logo, DisplayMetrics . DENSITY_MEDIUM ))+ " </img>\n " +
250250 " [L]\n " +
251251 " [C]<u><font size='big'>ORDER N°045</font></u>\n " +
@@ -272,7 +272,7 @@ printer
272272 " [L]\n " +
273273 " [C]<barcode type='ean13' height='10'>831254784551</barcode>\n " +
274274 " [C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>"
275- );
275+ );
276276```
277277
278278
@@ -465,6 +465,11 @@ Convert the mmSize variable from millimeters to dot.
465465- ** param** ` float mmSize ` : Distance in millimeters to be converted
466466- ** return** ` int ` : Dot size of mmSize.
467467
468+ #### Method : ` useEscAsteriskCommand(boolean enable) `
469+ Active "ESC * " command for image printing.
470+ - ** param** ` boolean enable ` : true to use "ESC * ", false to use "GS v 0"
471+ - ** return** ` Printer ` : Fluent interface
472+
468473#### Method : ` printFormattedText(String text) `
469474Print a formatted text and feed paper (20 millimeters). Read the [ "Formatted Text : Syntax guide" section] ( #formatted-text--syntax-guide ) for more information about text formatting options.
470475- ** param** ` String text ` : Formatted text to be printed.
0 commit comments