PrinterSDK

1.Call the printer via SDK

iMin SDK provides packaged common printing instructions, so that developers can quickly access iMin printers

Print Demo source code

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:

  1. 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:

  1. 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:

  1. size --> Set text size default 28

1IminPrintUtils.getInstance(TestPrintActivity.this).setTextSize(26);

8、Set font

Function:void setTextTypeface(Typeface typeface)

parameter:

  1. 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:

  1. 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:

  1. space --> Set line spacing default 1.0f

1IminPrintUtils.getInstance(TestPrintActivity.this).setTextLineSpacing(1.0f);

11、Set print width

Function:void setTextWidth(int width)

parameter:

  1. width --> Default 80mm printer default effective print width 576

1IminPrintUtils.getInstance(TestPrintActivity.this).setTextWidth(576);

12、Print text

Function:void printText(String text)

parameter:

  1. text --> Print content; will automatically wrap

1IminPrintUtils.getInstance(TestPrintActivity.this).printText("PrinterTestContent");

13、Print text

Function:void printText(String text, int type)

parameter:

  1. 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.

  2. 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:

  1. colTextArr --> column text string array

  2. 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.

  3. colAlign --> alignment: 0 to the left, 1 to the center, and 2 to the right

  4. size --> Font size per column string array

  5. 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:

  1. 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:

  1. 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:

  1. 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:

  1. barCodeType --> barcode type 0 <= barcodeType <= 6 and barcodeType=73

  2. 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:

  1. barCodeType --> barcode type 0 <= barcodeType <= 6 and barcodeType=73

  2. 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

  3. 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:

  1. 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:

  1. 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:

  1. marginValue --> Left Spacing Value 0-576

1IminPrintUtils.getInstance(TestPrintActivity.this).setLeftMargin(100);

23、Printer QR code

Function:void printQrCode(String qrStr)

parameter:

  1. 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:

  1. qrStr --> QR code content.

  2. 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:

  1. style --> 0-80mm 1-58mm

1IminPrintUtils.getInstance(TestPrintActivity.this).setPageFormat(1);

26、Print bitmap

Function:void printSingleBitmap(Bitmap bitmap)

parameter:

  1. bitmap --> bitmap

1IminPrintUtils.getInstance(TestPrintActivity.this).printSingleBitmap(bitmap);

27、Print bitmap

Function:void printSingleBitmap(Bitmap bitmap, int alignmentMode)

parameter:

  1. bitmap --> Bitmap

  2. 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:

  1. bitmap --> bitmaps

1IminPrintUtils.getInstance(TestPrintActivity.this).printMultiBitmap(bitmaps);

29、Print multiple bitmaps

Function:void printMultiBitmap(List<Bitmap> bitmaps, int alignmentMode)

parameter:

  1. bitmap --> bitmaps

  2. alignmentMode --> 0 = Left / 1 = Center / 2 = Right.

1IminPrintUtils.getInstance(TestPrintActivity.this).printMultiBitmap(bitmaps, 1);

30、setDoubleQRSize

Function:void setDoubleQRSize(int size)

parameter:

  1. size –> 1<= size <= 8

  2. 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:
  1. level –> 0-3

  2. 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:
  1. marginValue –> Left Spacing Value 0-576

  2. 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:
  1. marginValue –> Left Spacing Value 0-576

  2. 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:
  1. version -> 0-40

  2. 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:
  1. version -> 0-40

  2. 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:
  1. colTextArr –> column text string array

  2. 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.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

  1. Establish a connection with the Bluetooth device.

  2. Splice the instructions and text into Bytes.

  3. Send to BluetoothPrinter.

  4. The underlying printing service drives the printing device to complete printing.