Skip to content

Commit b79bf91

Browse files
committed
v3.2.0
1 parent c1a56fc commit b79bf91

File tree

4 files changed

+90
-80
lines changed

4 files changed

+90
-80
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
```
6666
allprojects {
@@ -76,7 +76,7 @@ allprojects {
7676
```
7777
dependencies {
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

@@ -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)`
469474
Print 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.

escposprinter/README.md

Lines changed: 79 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
```
6666
allprojects {
@@ -76,7 +76,7 @@ allprojects {
7676
```
7777
dependencies {
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
9292
if (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
110110
EscPosPrinter 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

142142
Below 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
157157
new 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
206206
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
207207
private 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

224224
public 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
246246
EscPosPrinter 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)`
469474
Print 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.

escposprinter/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.library'
22

3-
def libraryVersionCode = 3001002
4-
def libraryVersionName = "3.1.2"
3+
def libraryVersionCode = 3002000
4+
def libraryVersionName = "3.2.0"
55

66
android {
77
compileSdkVersion 31

escposprinter/src/main/java/com/dantsu/escposprinter/EscPosPrinter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public EscPosPrinter disconnectPrinter() {
6969
}
7070

7171
/**
72-
* Active "ESC *" command for image print.
72+
* Active "ESC *" command for image printing.
7373
*
7474
* @param enable true to use "ESC *", false to use "GS v 0"
7575
* @return Fluent interface

0 commit comments

Comments
 (0)