Skip to content

Commit b55f5da

Browse files
committed
Write sample code and README related to encoding function. #69
1 parent dcf50e2 commit b55f5da

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,25 @@ const networkPrinter = new escpos.Printer(networkDevice);
125125

126126
Escpos inherits its methods to the printers. the following methods are defined:
127127

128-
### text("text", encodeType)
128+
#### text("text", encodeType)
129129

130130
Prints raw text. Raises TextError exception.
131131

132132
For the encode type, see the [iconv-lite wiki document](https://github.com/ashtuchkin/iconv-lite/wiki/Supported-Encodings). Escpos uses `iconv-lite` for encoding.
133133

134134
If the type is undefined, the default type is GB18030.
135135

136-
### control("align")
136+
#### encode("encodeType")
137+
138+
Sets the encoding value globally. default type is GB18030 (Chinese)
139+
140+
```javascript
141+
printer
142+
.encode('EUC-KR')
143+
.text('동해물과 백두산이 마르고 닳도록');
144+
```
145+
146+
#### control("align")
137147

138148
Carrier feed and tabs.
139149

@@ -146,7 +156,7 @@ align is a string which takes any of the following values:
146156
+ VT for Vertical Tab
147157

148158

149-
### align("align")
159+
#### align("align")
150160

151161
Set text properties.
152162

@@ -158,16 +168,16 @@ align set horizontal position for text, the possible values are:
158168

159169
Default: LT
160170

161-
### font("type")
171+
#### font("type")
162172
font type could be A or B. Default: A
163173

164-
### size(width, heigth)
174+
#### size(width, heigth)
165175

166176
width is a numeric value, 1 is for regular size, and 2 is twice the standard size. Default: 1
167177

168178
height is a numeric value, 1 is for regular size and 2 is twice the standard size. Default: 1
169179

170-
### barcode("code", "barcodeType", width, height, "position", "font")
180+
#### barcode("code", "barcodeType", width, height, "position", "font")
171181

172182
Prints a barcode.
173183

@@ -204,7 +214,7 @@ Default: A
204214

205215
Raises BarcodeTypeError, BarcodeSizeError, BarcodeCodeError exceptions.
206216

207-
### cut("mode")
217+
#### cut("mode")
208218

209219
Cut paper.
210220

@@ -213,7 +223,7 @@ Partial cut is not implemented in all printers.
213223

214224
*** Don't foget this, because cut will flush buffer to printer ***
215225

216-
### cashdraw(pin)
226+
#### cashdraw(pin)
217227

218228
Sends a pulse to the cash drawer in the specified pin.
219229

examples/encode.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const escpos = require('../');
2+
3+
const device = new escpos.USB();
4+
// const device = new escpos.Network('localhost');
5+
// const device = new escpos.Serial('/dev/usb/lp0');
6+
const printer = new escpos.Printer(device);
7+
8+
device.open(function(err){
9+
10+
printer
11+
.font('a')
12+
.align('ct')
13+
.size(1, 1)
14+
.text('敏捷的棕色狐狸跳过懒狗') // default encoding set is GB18030
15+
.encode('EUC-KR') // set encode globally
16+
.text('동해물과 백두산이 마르고 닳도록')
17+
.text('こんにちは', 'EUC-JP') // set encode functional
18+
.cut();
19+
});

0 commit comments

Comments
 (0)