Print libraries for receipt printers, simple and easy with markdown, printer status support.
const markdown = `^^^RECEIPT
03/18/2024, 12:34:56 PM
Asparagus | 1| 1.00
Broccoli | 2| 2.00
Carrot | 3| 3.00
---
^TOTAL | ^6.00`;
const receipt = Receipt.from(markdown, '-c 42 -l en');
const png = await receipt.toPNG();
Receipt.js is simple print libraries for receipt printers that prints with easy markdown data for receipts and returns printer status. Even without a printer, it can output images.
A development tool is provided to edit, preview, and print the receipt markdown.
https://receiptline.github.io/receiptjs-designer/
The details of the receipt markdown are explained at
https://github.com/receiptline/receiptline
The following files are required to use the Receipt API.
- receipt.js
- qrcode.js (optional)
<script type="text/javascript" src="receipt.js"></script>
<script type="text/javascript" src="qrcode-generator/qrcode.js"></script>
const markdown = `^^^RECEIPT
03/18/2024, 12:34:56 PM
Asparagus | 1| 1.00
Broccoli | 2| 2.00
Carrot | 3| 3.00
---
^TOTAL | ^6.00`;
const receipt = Receipt.from(markdown, '-c 42 -l en');
const png = await receipt.toPNG();
The Receipt.from() static method creates a new Receipt instance.
markdown
<string>- receipt markdown text
options
<string>-c <chars>
: characters per line- range:
24
-96
- default:
48
- range:
-l <language>
: language of receipt markdown texten
,fr
,de
,es
,po
,it
,ru
, ...: Multilingual (cp437, 852, 858, 866, 1252 characters)ja
: Japanese (shiftjis characters)ko
: Korean (ksc5601 characters)zh-hans
: Simplified Chinese (gb18030 characters)zh-hant
: Traditional Chinese (big5 characters)th
: Thai- default: system locale
-s
: paper saving (reduce line spacing)
- A new Receipt instance.
The toPNG() instance method converts to PNG.
https://receiptline.github.io/receiptjs/test/topng.html
- None.
- A Promise that fulfills with a string once the PNG in data URL format is ready to be used.
The toSVG() instance method converts to SVG.
https://receiptline.github.io/receiptjs/test/tosvg.html
- None.
- A Promise that fulfills with a string once the SVG is ready to be used.
The toText() instance method converts to plain text.
https://receiptline.github.io/receiptjs/test/totext.html
- None.
- A Promise that fulfills with a string once the plain text is ready to be used.
The toString() instance method returns a string representing the receipt markdown text.
- None.
- A string representing the receipt markdown text.
The following files are required to use the Receipt Printer API.
- receipt.js
- receipt-printer.js
- qrcode.js (optional)
<script type="text/javascript" src="receipt.js"></script>
<script type="text/javascript" src="receipt-printer.js"></script>
<script type="text/javascript" src="qrcode-generator/qrcode.js"></script>
const markdown = `^^^RECEIPT
03/18/2024, 12:34:56 PM
Asparagus | 1| 1.00
Broccoli | 2| 2.00
Carrot | 3| 3.00
---
^TOTAL | ^6.00`;
const receipt = Receipt.from(markdown, '-p generic -c 42');
const command = await receipt.toCommand();
The Receipt.from() static method creates a new Receipt instance.
markdown
<string>- receipt markdown text
options
<string>-p <printer>
: printer control languageescpos
: ESC/POS (Epson)epson
: ESC/POS (Epson)sii
: ESC/POS (Seiko Instruments)citizen
: ESC/POS (Citizen)fit
: ESC/POS (Fujitsu)impact
: ESC/POS (TM-U220)impactb
: ESC/POS (TM-U220 Font B)generic
: ESC/POS (Generic) Experimentalstar
: StarPRNTstarline
: Star Line Modeemustarline
: Command Emulator Star Line Modestargraphic
: Star Graphic Modestarimpact
: Star Mode on dot impact printers Experimentalstarimpact2
: Star Mode on dot impact printers (Font 5x9 2P-1) Experimentalstarimpact3
: Star Mode on dot impact printers (Font 5x9 3P-1) Experimental
-c <chars>
: characters per line- range:
24
-96
- default:
48
- range:
-l <language>
: language of receipt markdown texten
,fr
,de
,es
,po
,it
,ru
, ...: Multilingual (cp437, 852, 858, 866, 1252 characters)ja
: Japanese (shiftjis characters)ko
: Korean (ksc5601 characters)zh-hans
: Simplified Chinese (gb18030 characters)zh-hant
: Traditional Chinese (big5 characters)th
: Thai- default: system locale
-s
: paper saving (reduce line spacing)-m [<left>][,<right>]
: print margin- range (left):
0
-24
- range (right):
0
-24
- default:
0,0
- range (left):
-u
: upside down-i
: print as image-n
: no paper cut-b <threshold>
: image thresholding- range:
0
-255
- default: error diffusion
- range:
-g <gamma>
: image gamma correction- range:
0.1
-10.0
- default:
1.0
- range:
-v
: landscape orientation- device font support:
escpos
,epson
,sii
,citizen
,star
- device font support:
-r <dpi>
:print resolution for ESC/POS, landscape, and device font- values:
180
,203
- default:
203
- values:
- A new Receipt instance.
The toCommand() instance method converts to printer commands.
https://receiptline.github.io/receiptjs/test/tocommand.html
- None.
- A Promise that fulfills with a string once the printer commands is ready to be used.
The following files are required to use the Receipt Serial API.
- receipt.js
- receipt-printer.js
- receipt-serial.js
- qrcode.js (optional)
<script type="text/javascript" src="receipt.js"></script>
<script type="text/javascript" src="receipt-printer.js"></script>
<script type="text/javascript" src="receipt-serial.js"></script>
<script type="text/javascript" src="qrcode-generator/qrcode.js"></script>
const markdown = `^^^RECEIPT
03/18/2024, 12:34:56 PM
Asparagus | 1| 1.00
Broccoli | 2| 2.00
Carrot | 3| 3.00
---
^TOTAL | ^6.00`;
const conn = ReceiptSerial.connect({ baudRate: 19200 });
conn.on('status', status => {
console.log(status);
});
conn.on('ready', async () => {
const result = await conn.print(markdown, '-c 42');
});
The ReceiptSerial.connect() static method creates a new connection using the Web Serial API.
options
<object>baudRate
: baud rate to establish serial communication- default:
115200
- default:
- other values
- parity:
none
- data bits:
8
- stop bits:
1
- flow control:
hardware
- parity:
These options are for real serial ports.
- A new ReceiptSerial instance.
The receiptSerial.status instance property is a string representing the printer status.
- A string representing the printer status.
online
: printer is onlineprint
: printer is printingcoveropen
: printer cover is openpaperempty
: no receipt papererror
: printer error (except cover open and paper empty)offline
: printer is off or offlinedisconnect
: printer is not connected
The print() instance method prints a receipt markdown text.
https://receiptline.github.io/receiptjs/test/print.html
markdown
<string>- receipt markdown text
options
<string>-c <chars>
: characters per line- range:
24
-96
- default:
48
- range:
-l <language>
: language of receipt markdown texten
,fr
,de
,es
,po
,it
,ru
, ...: Multilingual (cp437, 852, 858, 866, 1252 characters)ja
: Japanese (shiftjis characters)ko
: Korean (ksc5601 characters)zh-hans
: Simplified Chinese (gb18030 characters)zh-hant
: Traditional Chinese (big5 characters)th
: Thai- default: system locale
-s
: paper saving (reduce line spacing)-m [<left>][,<right>]
: print margin- range (left):
0
-24
- range (right):
0
-24
- default:
0,0
- range (left):
-u
: upside down-i
: print as image-n
: no paper cut-b <threshold>
: image thresholding- range:
0
-255
- default: error diffusion
- range:
-g <gamma>
: image gamma correction- range:
0.1
-10.0
- default:
1.0
- range:
-p <printer>
: printer control languageescpos
: ESC/POS (Epson)epson
: ESC/POS (Epson)sii
: ESC/POS (Seiko Instruments)citizen
: ESC/POS (Citizen)fit
: ESC/POS (Fujitsu)impact
: ESC/POS (TM-U220)impactb
: ESC/POS (TM-U220 Font B)generic
: ESC/POS (Generic) Experimentalstar
: StarPRNTstarline
: Star Line Modeemustarline
: Command Emulator Star Line Modestargraphic
: Star Graphic Modestarimpact
: Star Mode on dot impact printers Experimentalstarimpact2
: Star Mode on dot impact printers (Font 5x9 2P-1) Experimentalstarimpact3
: Star Mode on dot impact printers (Font 5x9 3P-1) Experimental- default: auto detection (
epson
,sii
,citizen
,fit
,impactb
,generic
,star
)
-v
: landscape orientation- device font support:
escpos
,epson
,sii
,citizen
,star
- device font support:
-r <dpi>
:print resolution for ESC/POS, landscape, and device font- values:
180
,203
- default:
203
- values:
- A Promise that fulfills with a string once the print result is ready to be used.
success
: printing successprint
: printer is printingcoveropen
: printer cover is openpaperempty
: no receipt papererror
: printer error (except cover open and paper empty)offline
: printer is off or offlinedisconnect
: printer is not connected
The close() instance method closes the connection.
The current implementation also closes other open connections.
- None.
- None.
The on() instance method adds the listener
function to the listeners array for the event named name
.
name
- event name
status
: printer status updatedready
: ready to printonline
: printer is onlineprint
: printer is printingcoveropen
: printer cover is openpaperempty
: no receipt papererror
: printer error (except cover open and paper empty)offline
: printer is off or offlinedisconnect
: printer is not connected
- event name
listener
- the listener function
- None.
The off() instance method removes the listener
function from the listeners array for the event named name
.
name
- event name
status
: printer status updatedready
: ready to printonline
: printer is onlineprint
: printer is printingcoveropen
: printer cover is openpaperempty
: no receipt papererror
: printer error (except cover open and paper empty)offline
: printer is off or offlinedisconnect
: printer is not connected
- event name
listener
- the listener function
- None.
- Modern Web browsers
The print function is available on Chrome, Edge, and Opera for PCs that support the Web Serial API.
(Windows, Linux, macOS, and ChromeOS)
- Epson TM series
- Seiko Instruments RP series
- Star MC series
- Citizen CT series
- Fujitsu FP series
Connect with the Web Serial API.
(Bluetooth, virtual serial port, and serial port)
Epson TM series (South Asia model) and Star MC series (StarPRNT model) can print with device font of Thai characters.
Closing the virtual port to which no printer is connected may cause the browser to stop responding.
Please change the signal line setting to "RS-232C cross cable".
If the printer goes offline during print data transmission and the virtual port is closed, the browser may stop responding.
In this case, press the printer's paper feed button.
- Receipt.js
- Apache License, Version 2.0
- QR Code Generator for JavaScript with UTF8 Support
- MIT License