PrinterSDK
1.Call the printer via SDK
iMin SDK provides packaged common printing instructions, so that developers can quickly access iMin printers
1、Printer initialization
Function:void initPrinter()
Remarks:Reset the printer’s logic program (for example: layout settings, bold and other style settings), but do not clear the buffer data, so unfinished print jobs will continue after reset.
1IminPrintUtils.getInstance(TestPrintActivity.this).initPrinter(IminPrintUtils.PrintConnectType.SPI);
parameter:
IminPrintUtils.PrintConnectType.USB –> USB
IminPrintUtils.PrintConnectType.SPI –> SPI
IminPrintUtils.PrintConnectType.Bluetooth –> Bluetooth
2、Get printer status
Function by USB(D4&S1):int getPrinterStatus(IminPrintUtils.PrintConnectType type)
Function by SPI(M2):void getPrinterStatus(IminPrintUtils.PrintConnectType type, final Callback callback)
return value:
-1 –> The printer is not connected or powered on
0 –> The printer is normal
1 –> The printer is not connected or powered on
3 –> Print head open
7 –> No Paper Feed
8 –> Paper Running Out
99 –> Other errors
1 int status = IminPrintUtils.getInstance(TestPrintActivity.this).getPrinterStatus(IminPrintUtils.PrintConnectType.USB );
2
3 IminPrintUtils.getPrinterStatus(IminPrintUtils.PrintConnectType.SPI, new Callback() {
4 @Override
5 public <T> void callback(T t) {
6 int status = (int) t;
7 }
8 });
3、Print and feed paper
Function:void printAndLineFeed()
Remarks:The printer runs on 1 lines of paper
1IminPrintUtils.getInstance(TestPrintActivity.this).printAndLineFeed();
4、Print blank lines (custom height)
Function:void printAndFeedPaper(int value)
Remarks:The maximum paper distance is 1016mm (40 inches), if this distance is exceeded, the maximum distance is taken
parameter:
value –> height(0-255).
1IminPrintUtils.getInstance(TestPrintActivity.this).printAndFeedPaper(100);
5、 Cutter (paper cutting) correlation
Function:void partialCut()
Remarks:equipment support is required
1IminPrintUtils.getInstance(TestPrintActivity.this).partialCut();
6、Set text alignment
Function:void setAlignment(int alignment)
parameter:
alignment –> Set text alignment 0 = left / 1 = center / 2 = right / default = 0
1IminPrintUtils.getInstance(TestPrintActivity.this).setAlignment(1);
7、Set text size
Function:void setTextSize(int size)
parameter:
size –> Set text size default 28
1IminPrintUtils.getInstance(TestPrintActivity.this).setTextSize(26);
8、Set font
Function:void setTextTypeface(Typeface typeface)
parameter:
typeface –>Set font default Typeface.DEFAULT
–> Set Monospace font type Typeface.MONOSPACE
—> Set Bold font type Typeface.DEFAULT_BOLD
–> Set Sans Seriff font type Typeface.SANS_SERIF
—> Set Serif font type Typeface.SERIF
1IminPrintUtils.getInstance(TestPrintActivity.this).setTextTypeface(Typeface.DEFAULT);
9、Set font style
Function:void setTextStyle(int style)
parameter:
style –> Set the font style (bold or italic) NORMAL = 0 BOLD = 1 ITALIC = 2 BOLD_ITALIC = 3
1IminPrintUtils.getInstance(TestPrintActivity.this).setTextStyle(1);
10、Set line spacing
Function:void setTextLineSpacing(float space)
parameter:
space –> Set line spacing default 1.0f
1IminPrintUtils.getInstance(TestPrintActivity.this).setTextLineSpacing(1.0f);
11、Set print width
Function:void setTextWidth(int width)
parameter:
width –> Default 80mm printer default effective print width 576
1IminPrintUtils.getInstance(TestPrintActivity.this).setTextWidth(576);
12、Print text
Function:void printText(String text)
parameter:
text –> Print content; will automatically wrap
1IminPrintUtils.getInstance(TestPrintActivity.this).printText("PrinterTestContent");
13、Print text
Function:void printText(String text, int type)
parameter:
text –> When the printed content is less than one or more lines, you need to add a line break “n” at the end of the content to print it immediately, otherwise it will be cached in the buffer.
type –> Default value 0;
0 = you need to add a line break “n” at the end of the content to print it immediately, otherwise it will be cached in the buffer.
1 = Word wrap
Note: to change the style of the printed text (such as alignment, font size, bold, etc.),set it before calling the printText method.
1IminPrintUtils.getInstance(TestPrintActivity.this).printText("PrinterTestContent", 0);
14、Print a row of the table (not support Arabic)
Function:void printColumnsText(String[] colTextArr, int[] colWidthArr, int[] colAlign, int width, int[] size)
parameter:
colTextArr –> column text string array
colWidthArr –> Array of the width of each column, calculated in English characters, each Chinese character occupies two English characters, each width is greater than 0.
colAlign –> alignment: 0 to the left, 1 to the center, and 2 to the right
size –> Font size per column string array
width –> Print the total width of a line (80mm printing paper = 576)
1IminPrintUtils.getInstance(TestPrintActivity.this).printColumnsText(new String[]{"1","iMin","iMin"} ,new String[]{1,2,1} ,new String[]{1,0,2} ,new String[]{26,26,26} ,576);
15、Set barcode width
Function:void setBarCodeWidth(int width)
parameter:
width –> barcode width level 2 <= width <= 6 If you do not set the default barcode width level to 3
1IminPrintUtils.getInstance(TestPrintActivity.this).setBarCodeWidth(4);
16、Set the height of the barcode
Function:void setBarCodeHeight(int height)
parameter:
height –> barcode height 1 <= height <= 255 Same as above, every 8 points is 1mm
1IminPrintUtils.getInstance(TestPrintActivity.this).setBarCodeHeight(100);
17、When printing barcodes, select the printing position for HRI characters
Function:void setBarCodeContentPrintPos(int position)
parameter:
position –> position HRI character printing position
0 –> Do not print
1 –> Above the barcode
2 –> Below the barcode
3 –> Barcodes are printed above and below
1IminPrintUtils.getInstance(TestPrintActivity.this).setBarCodeContentPrintPos(2);
18、Print barcode
Function:void printBarCode(int barCodeType, String barCodeContent) throws UnsupportedEncodingException
parameter:
barCodeType –> barcode type 0 <= barcodeType <= 6 and barcodeType=73
barCodeContent –> Printed barcode character content, if it is code128 printing, you need to add {A ,{B or {C in front,you can see the following example
note:
barcodeType value Supported barcode content length Supported ASCII code range 0 --> UPC-A barCodeContent.length = 11,12 48 ≤range≤ 57 1 --> UPC-E barCodeContent.length = 11,12 48 ≤range≤ 57 2 --> JAN13 / EAN13 barCodeContent.length = 12,13 48 ≤range≤ 57 3 --> JAN8 / EAN8 barCodeContent.length = 7 48 ≤range≤ 57 4 --> CODE39 barCodeContent.length >=1 48≤range≤57,65≤range≤90,range = 32, 36, 37, 42, 43, 45, 46, 47 5 --> ITF barCodeContent.length >=2 48 ≤range≤ 57 6 --> CODABAR barCodeContent.length >=2 48≤range≤57, 65≤range≤68,97≤range≤100,range = 36, 43, 45, 46, 47, 58 73 -->CODE128 barCodeContent.length >=2 0≤range≤127
1IminPrintUtils.getInstance(TestPrintActivity.this).printBarCode(2 ,"012345678912");
2IminPrintUtils.getInstance(TestPrintActivity.this).printBarCode(73 ,"{B012345678912");
19、Print barcode
Function:void printBarCode(int barCodeType, String barCodeContent, int alignmentMode) throws UnsupportedEncodingException
parameter:
barCodeType –> barcode type 0 <= barcodeType <= 6 and barcodeType=73
barCodeContent –> Printed barcode character content, if it is code128 printing, you need to add {A ,{B or {C in front,you can see the following example
alignmentMode –> 0 = Left / 1 = Center / 2 = Right
note:
barcodeType value Supported barcode content length Supported ASCII code range 0 --> UPC-A barCodeContent.length = 11,12 48 ≤range≤ 57 1 --> UPC-E barCodeContent.length = 11,12 48 ≤range≤ 57 2 --> JAN13 / EAN13 barCodeContent.length = 12,13 48 ≤range≤ 57 3 --> JAN8 / EAN8 barCodeContent.length = 7 48 ≤range≤ 57 4 --> CODE39 barCodeContent.length >=1, 48≤range≤57,65≤range≤90,range = 32, 36, 37, 42, 43, 45, 46, 47 5 --> ITF barCodeContent.length >=2 48 ≤range≤ 57 6 --> CODABAR barCodeContent.length >=2 48≤range≤57, 65≤range≤68,97≤range≤100,range = 36, 43, 45, 46, 47, 58 73 --> CODE128 barCodeContent.length >=2 0≤range≤127
1IminPrintUtils.getInstance(TestPrintActivity.this).printBarCode(2 ,"0123456789012", 1);
2IminPrintUtils.getInstance(TestPrintActivity.this).printBarCode(73 ,"{B012345678912",1);
20、Set the size of the QR code
Function:void setQrCodeSize(int level)
parameter:
level –> QR code block size, unit: dot, 1 <= level <= 16
1IminPrintUtils.getInstance(TestPrintActivity.this).setQrCodeSize(2);
21、Set QR code error correction
Function:void setQrCodeErrorCorrectionLev(int level)
parameter:
level –> level >= 48 && level <= 51
1IminPrintUtils.getInstance(TestPrintActivity.this).setQrCodeErrorCorrectionLev(51);
22、Set left margin of barcode and QR code
Function:void setLeftMargin(int marginValue)
parameter:
marginValue –> Left Spacing Value 0-576
1IminPrintUtils.getInstance(TestPrintActivity.this).setLeftMargin(100);
23、Printer QR code
Function:void printQrCode(String qrStr)
parameter:
qrStr –> QR code content.
1IminPrintUtils.getInstance(TestPrintActivity.this).printQrCode("https://www.imin.sg");
24、Printer QR code
Function:void printQrCode(String qrStr, int alignmentMode)
parameter:
qrStr –> QR code content.
alignmentMode –> 0 = Left / 1 = Center / 2 = Right.
1IminPrintUtils.getInstance(TestPrintActivity.this).printQrCode("https://www.imin.sg", 1);
25、Set paper specifications
Function:void setPageFormat(int style)
parameter:
style –> 0-80mm 1-58mm
1IminPrintUtils.getInstance(TestPrintActivity.this).setPageFormat(1);
26、Print bitmap
Function:void printSingleBitmap(Bitmap bitmap)
parameter:
bitmap –> bitmap
1IminPrintUtils.getInstance(TestPrintActivity.this).printSingleBitmap(bitmap);
27、Print bitmap
Function:void printSingleBitmap(Bitmap bitmap, int alignmentMode)
parameter:
bitmap –> Bitmap
alignmentMode –> 0 = Left / 1 = Center / 2 = Right.
1IminPrintUtils.getInstance(TestPrintActivity.this).printSingleBitmap(bitmap, 1);
28、Print multiple bitmaps
Function:void printMultiBitmap(List<Bitmap> bitmaps)
parameter:
bitmap –> bitmaps
1IminPrintUtils.getInstance(TestPrintActivity.this).printMultiBitmap(bitmaps);
29、Print multiple bitmaps
Function:void printMultiBitmap(List<Bitmap> bitmaps, int alignmentMode)
parameter:
bitmap –> bitmaps
alignmentMode –> 0 = Left / 1 = Center / 2 = Right.
1IminPrintUtils.getInstance(TestPrintActivity.this).printMultiBitmap(bitmaps, 1);
30、setDoubleQRSize
Function:void setDoubleQRSize(int size)
parameter:
size –> 1<= size <= 8
Note: The setDoubleQRSize method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).setDoubleQRSize(1)
31、setDoubleQR2Level
Function:void setDoubleQR2Level(int level)
- parameter:
level –> 0-3
Note: The setDoubleQR2Level method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).setDoubleQR2Level(16)
32、setDoubleQR1MarginLeft
Function:void setDoubleQR1MarginLeft(int marginValue)
- parameter:
marginValue –> Left Spacing Value 0-576
Note: The setDoubleQR1MarginLeft method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).setDoubleQR1MarginLeft(26)
33、setDoubleQR2MarginLeft
Function void setDoubleQR2MarginLeft(int marginValue)
- parameter:
marginValue –> Left Spacing Value 0-576
Note: The setDoubleQR2MarginLeft method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).setDoubleQR2MarginLeft(26)
34、setDoubleQR1Version
Function:void setDoubleQR1Version(int version)
- parameter:
version -> 0-40
Note: The setDoubleQR1Version method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).setDoubleQR1Version(40)
35、setDoubleQR2Version
Function:void setDoubleQR2Version( int version)
- parameter:
version -> 0-40
Note: The setDoubleQR2Version method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).setDoubleQR2Version(40)
36、printDoubleQR
Function: void printDoubleQR(String[] colTextArr)
- parameter:
colTextArr –> column text string array
Note: The printDoubleQR method only supports models M2-203, M2 Pro, M2 Max, and D1
1IminPrintUtils.getInstance(TestPrintActivity.this).printDoubleQR(new String[]{"www.iMin.sg", "www.google.com"});
2.Transaction print
Note
At present, only M2-202, M2-203, M2 Pro products are supported, and other products are gradually opened.
To use transactional printing, you must import V1.1.0_2307141412.jar(or later)
Transaction print specification
Queue printing mode is used when you need to control the context of printing and get the result of printing (eg: whether the receipt was printed).
When enter the Queue printing mode, a printing queue buffer is created.
The printing content will be put into a queue first, and the printer does not print content until all the print content is put into the queue. When the queue printing is submitted, the printing tasks will be executed.
At the end of each printing queue, it will receive a feedback of the printing results of the Queue printing.
So the application can get the printing status of each transaction. eg: It can automatically re-print the whole receipt when replace a new roll of paper with “out of paper”.
Transaction print code example
1mIminPrintUtils.enterPrinterBuffer(true); //Enter transaction mode, after which all commands do not print immediately
2mIminPrintUtils.printText("Receipt 1\n");
3
4mIminPrintUtils.setAlignment(2);
5mIminPrintUtils.printText("Order No.220411A0015\n");
6
7mIminPrintUtils.setTextSize(48);
8mIminPrintUtils.setAlignment(1);
9mIminPrintUtils.setTextStyle(Typeface.BOLD);
10mIminPrintUtils.printText("Delivery charge:15.00\n");
11mIminPrintUtils.setTextSize(26);
12mIminPrintUtils.setAlignment(0);
13mIminPrintUtils.setTextStyle(Typeface.NORMAL);
14mIminPrintUtils.printAndFeedPaper(20);
15mIminPrintUtils.printAndFeedPaper(5);
16mIminPrintUtils.printText("Order No.220411A0015\n");
17
18//Other print content
19mIminPrintUtils.commitPrinterBuffer(callback); //A transaction is submitted, at which point the printer will start printing, and when printing success or failure will be returned in the callback
20//Wait for the return of the last transaction/automatically reprint if it fails
21
22mIminPrintUtils.printText("Receipt 2\n");
23
24mIminPrintUtils.setAlignment(2);
25mIminPrintUtils.printText("Order No.220411A0015\n");
26
27mIminPrintUtils.setTextSize(48);
28mIminPrintUtils.setAlignment(1);
29mIminPrintUtils.setTextStyle(Typeface.BOLD);
30mIminPrintUtils.printText("Delivery charge:15.00\n");
31mIminPrintUtils.setTextSize(26);
32mIminPrintUtils.setAlignment(0);
33mIminPrintUtils.setTextStyle(Typeface.NORMAL);
34mIminPrintUtils.printAndFeedPaper(20);
35mIminPrintUtils.printAndFeedPaper(5);
36mIminPrintUtils.printText("Order No.220411A0015\n");
37//Other print content
38mIminPrintUtils.commitPrinterBuffer(callback); //Continue to commit the next transaction
39
40mIminPrintUtils.exitPrinterBuffer(true, callback); //Exit transaction printing
Interface description
Function: void enterPrinterBuffer(boolean clean)
Remark:Enter transaction print mode parameter:
clean –> Whether to clear queue data. The value is true= clear /false= No clear
1void enterPrinterBuffer(true);
Function: void commitPrinterBuffer(PrintResultCallback callback)
Remark:Commit the transaction to print and call back the result parameter:
callback –> Result callback
1void commitPrinterBuffer(new PrintResultCallback() {
2 @Override
3 public void printResult(int result) {
4 Log.d(TAG, "exitPrinterBuffer printResult: " + result);
5 showToast(result + "");
6 /**48= Success
7 *49= Missing paper or print hatch door open
8 *50= Print hatch open
9 *52= Print head overheating
10 */
11 }
12});
Function: void exitPrinterBuffer(Boolean commit,PrintResultCallback callback)
Remark:Exit transaction print mode and call back the result parameter:
commit –> true: exit the transaction after printing, false: exit the transaction directly
callback –> Result callback
1mIminPrintUtils.exitPrinterBuffer(true, new PrintResultCallback() {
2 @Override
3 public void printResult(int result) {
4 Log.d(TAG, "exitPrinterBuffer printResult: " + result);
5 showToast(result + "");
6 /**48= Success
7 *49= Missing paper or print hatch door open
8 *50= Print hatch open
9 *52= Print head overheating
10 */
11 }
12});
3.Use the built-in virtual blueprint to call the printer
Introduction to Virtual Blue
In the bluetooth device list, you can see a paired and always-existing bluetooth device “BluetoothPrinter”, which is a printer device virtualized by the operating system and does not actually exist. Some of these special commands are iMin self-defined commands, such as:
Use of Virtual Blue
Establish a connection with the Bluetooth device.
Splice the instructions and text into Bytes.
Send to BluetoothPrinter.
The underlying printing service drives the printing device to complete printing.