External Printer
External Printer
1
Printer—Developer Documentation
Introduction ........................................................................................................................................... 3
Quick Start .............................................................................................................................................3
Introduction to API: ...............................................................................................................................5
1. Specify the printer of current SDK for operation ...........................................................................5
2. Connect the printer ......................................................................................................................... 5
3. Disconnect the printer .................................................................................................................... 5
4. Get the printer’s mac address list bound to Bluetooth ................................................................... 5
5. The connection status of the printer with specified enumeration type ...........................................5
6. Printer initialization ........................................................................................................................5
7. Move the paper according to line height ........................................................................................ 5
8. Move the paper according to pixels ............................................................................................... 6
9. Refresh buffer area ......................................................................................................................... 6
10. Horizontal anchor ......................................................................................................................... 6
11. Set the horizontal anchor .............................................................................................................. 6
12. Print text ....................................................................................................................................... 6
13. Set gb18030 character set coding .................................................................................................6
14. Set printer’s mapping page table .................................................................................................. 7
15. Set the international character set encoding ................................................................................. 7
16. Set the right spacing of characters ................................................................................................7
17. Set the left and right spacing between Chinese characters ...........................................................7
18. Set font size .................................................................................................................................. 7
19. Set alignment mode ...................................................................................................................... 7
20. Set absolute position .....................................................................................................................7
21. Set relative position ...................................................................................................................... 8
22. Enable or disable underline .......................................................................................................... 8
23. Enable or disable bold .................................................................................................................. 8
24. Enable or disable overlap effect (usually the same as bold) ........................................................ 8
25. Set the line spacing for the printer ................................................................................................8
26. Set the left spacing of the printer ..................................................................................................8
27. Set printing width ......................................................................................................................... 8
28. Print a barcode ..............................................................................................................................8
29. Print a QR code ............................................................................................................................ 9
30. Method 1 for printing an image ....................................................................................................9
31. Method 2 for printing an image ....................................................................................................9
32. Cutter cutting paper ...................................................................................................................... 9
33. Print a form ...................................................................................................................................9
34. Send data instructions .................................................................................................................10
35. Get printer status ........................................................................................................................ 10
36. LAN transaction printing interface of cloud printer ...................................................................10
Enable transaction mode ......................................................................................................................10
Submit transaction mode ..................................................................................................................... 10
Exit transaction mode .......................................................................................................................... 11
2
Printer—Developer Documentation
Introduction
There are two main SUNMI printer types: inbuilt printer and external printer. This document introduces how to use
APIs we provided to get your external printers ready for use quickly. For inbuilt printer documentation, please see
Inbuilt Printer Documentation.
You can call various print interface libraries in a fast way through simple API integration, and the interface libraries
basically have all the functions including printing layout, pattern setting, etc., and will be updated regularly to save your
time on learning printer configuration, ESC commands, etc.
Currently, printers supported by SDK for connection include 58mm Cloud Printer, 80mm Kitchen Cloud Printer, 58mm
Thermal Receipt Printer and so on.
Quick Start
1. Automatic integration:
Add dependencies and attributes configuration in the program build.gradle file:
dependencies{
compile ‘com.sunmi:external-printerlibrary:1.0.9’
}
Note: the dependency library is located in the maven central repository, so mavenCentral() support is required.
-dontwarn com.sunmi.externalprinteribrary.**
-keep public class com.sunmi.externalprinterlibrary.**{*;}
3. Select the corresponding enumeration type for SUNMI printer and specify it as the operation object of SDK.
The available types are:
//1. Specify 58mm Thermal Receipt Printer as the operation object of SDK
SunmiPrinterApi.gtInstance.setPrinter(SunmiPrinter.SunmiNTPrinter);
void onFound(){
//If the printer is found, it will call back this method
}
void onUnfound(){
//If the printer is not found, it will call back this method
3
Printer—Developer Documentation
}
void onConnect(){
//It will call back this method after successful connection, and the printer is ready
}
void onDisconnect(){
//It will call back this method if the printer is disconnected during the connection, and the printing task will be
interrupted
}
});
//3. Call the printing interface and complete the printing task
SunmiPrinterApi.getInstance().printInit();
SunmiPrinterApi.getInstance().printText(“123456789\n”);
SunmiPrinterApi.getInstance().printQrCode(“123456789, 4, 0);
5. Specify multiple printers connected via a LAN to print (same for the printers connected via Bluetooth)
void onFound(){
//If the printer is found, it will call back this method
}
void onUnfound(){
//If the printer is not found, it will call back this method
}
void onConnect(){
//It will call back this method after successful connection, and printing is ready
}
void onDisconnect(){
//It will call back this method if the printer is disconnected during the connection, and the printing task will be
interrupted
}
});
SunmiPrinterApi.getInstance().setPrinter(SunmiPrinter.SunmiNetPrinter,
“192.168.1.91”);
SunmiPrinterApi.getInstance().connectPrinter(…);
//2. Specify all the printers connected via LAN to print after successful connection
SunmiPrinterApi.setPrinter(SunmiPrinter.SunmiNetPrinter);
“192.168.1.91”);
SunmiPrinterApi.getInstance().disconnect(context);
Introduction to APIs:
5. Get the connection status of the printer with specified enumeration type
6. Printer initialization
- 5-
Printer—Developer Documentation
Method void lineWrap(int n)
Description The printer moves the paper for n lines;
If there is data in the printer buffer area, the printer will output the data and move the paper for n
lines;
The moving distance is 0 if the line height is set to 0.
Input Number of lines (0<n<256)
Return None
6
Printer—Developer Documentation
17. Set the left and right sidebearing between Chinese characters
- 7-
Printer—Developer Documentation
Return None
Method void printBarCode(String code, int type, int width, int height, int hriPos)
8
Printer—Developer Documentation
- 9-
Printer—Developer Documentation
Description Output the printing result in a form format, and each array represents the data and format on this
column. You need to call this method for several times to achieve the form format.
! Note: calling this method will initialize the mode set before.
Input colsTextArr: the content to be printed in each column, Chinese and ascii code supported;
colsWidthArr: the maximum number of characters that can be contained in a column, and the
characters are expressed in ascii code (one Chinese character is equal to two ascii characters).
When the text exceeds the maximum number of characters that can be contained in a column, the
text will be moved to the next row of the column. When the maximum number of characters in all
columns exceeds the maximum number of characters that can be contained in a row, the text will
not be printed;
colsAlign: the alignment of the content of each column, and it is only effective when the number
of text characters is less than the maximum number of characters.
Return None
For scenarios requiring LAN printing, we provide the following extension methods. You can enable and submit
the information before and after printing to obtain the actual printing results.
You can call by the following method:
Enable transaction - > Print SDK - > Submit transaction - > Wait for The printing result callback
The detailed methods are as follows:
Note: currently only LAN printing of cloud printer supports transaction mode.
Input Callback: the transaction submission result
Return None
- 11 -