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. .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 0 int status = IminPrintUtils.getInstance(TestPrintActivity.this).getPrinterStatus(IminPrintUtils.PrintConnectType.USB ); IminPrintUtils.getPrinterStatus(IminPrintUtils.PrintConnectType.SPI, new Callback() { @Override public void callback(T t) { int status = (int) t; } }); **3、Print and feed paper** Function:void printAndLineFeed() Remarks:The printer runs on 1 lines of paper .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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). .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).printAndFeedPaper(100); **5、 Cutter (paper cutting) correlation** Function:void partialCut() Remarks:equipment support is required .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).setAlignment(1); **7、Set text size** Function:void setTextSize(int size) parameter: 1. size --> Set text size default 28 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).setTextStyle(1); **10、Set line spacing** Function:void setTextLineSpacing(float space) parameter: 1. space --> Set line spacing default 1.0f .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).setTextWidth(576); **12、Print text** Function:void printText(String text) parameter: 1. text --> Print content; will automatically wrap .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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. .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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) .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).printBarCode(2 ,"012345678912"); IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).printBarCode(2 ,"0123456789012", 1); IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).setQrCodeSize(2); **21、Set QR code error correction** Function:void setQrCodeErrorCorrectionLev(int level) parameter: 1. level --> level >= 48 && level <= 51 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).setLeftMargin(100); **23、Printer QR code** Function:void printQrCode(String qrStr) parameter: 1. qrStr --> QR code content. .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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. .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).setPageFormat(1); **26、Print bitmap** Function:void printSingleBitmap(Bitmap bitmap) parameter: 1. bitmap --> bitmap .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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. .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).printSingleBitmap(bitmap, 1); **28、Print multiple bitmaps** Function:void printMultiBitmap(List bitmaps) parameter: 1. bitmap --> bitmaps .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.getInstance(TestPrintActivity.this).printMultiBitmap(bitmaps); **29、Print multiple bitmaps** Function:void printMultiBitmap(List bitmaps, int alignmentMode) parameter: 1. bitmap --> bitmaps 2. alignmentMode --> 0 = Left / 1 = Center / 2 = Right. .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: xml :linenos: :emphasize-lines: 1 IminPrintUtils.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 .. code-block:: java :linenos: :emphasize-lines: 1 IminPrintUtils.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) 1. 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". 2. Transaction print code example .. code-block:: java :linenos: :emphasize-lines: 1 mIminPrintUtils.enterPrinterBuffer(true); //Enter transaction mode, after which all commands do not print immediately mIminPrintUtils.printText("Receipt 1\n"); mIminPrintUtils.setAlignment(2); mIminPrintUtils.printText("Order No.220411A0015\n"); mIminPrintUtils.setTextSize(48); mIminPrintUtils.setAlignment(1); mIminPrintUtils.setTextStyle(Typeface.BOLD); mIminPrintUtils.printText("Delivery charge:15.00\n"); mIminPrintUtils.setTextSize(26); mIminPrintUtils.setAlignment(0); mIminPrintUtils.setTextStyle(Typeface.NORMAL); mIminPrintUtils.printAndFeedPaper(20); mIminPrintUtils.printAndFeedPaper(5); mIminPrintUtils.printText("Order No.220411A0015\n"); //Other print content mIminPrintUtils.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 //Wait for the return of the last transaction/automatically reprint if it fails mIminPrintUtils.printText("Receipt 2\n"); mIminPrintUtils.setAlignment(2); mIminPrintUtils.printText("Order No.220411A0015\n"); mIminPrintUtils.setTextSize(48); mIminPrintUtils.setAlignment(1); mIminPrintUtils.setTextStyle(Typeface.BOLD); mIminPrintUtils.printText("Delivery charge:15.00\n"); mIminPrintUtils.setTextSize(26); mIminPrintUtils.setAlignment(0); mIminPrintUtils.setTextStyle(Typeface.NORMAL); mIminPrintUtils.printAndFeedPaper(20); mIminPrintUtils.printAndFeedPaper(5); mIminPrintUtils.printText("Order No.220411A0015\n"); //Other print content mIminPrintUtils.commitPrinterBuffer(callback); //Continue to commit the next transaction mIminPrintUtils.exitPrinterBuffer(true, callback); //Exit transaction printing 3. Interface description Function: void enterPrinterBuffer(boolean clean) Remark:Enter transaction print mode parameter: 1. clean –> Whether to clear queue data. The value is true= clear /false= No clear .. code-block:: java :linenos: :emphasize-lines: 1 void enterPrinterBuffer(true); Function: void commitPrinterBuffer(PrintResultCallback callback) Remark:Commit the transaction to print and call back the result parameter: 1. callback –> Result callback .. code-block:: java :linenos: :emphasize-lines: 1 void commitPrinterBuffer(new PrintResultCallback() { @Override public void printResult(int result) { Log.d(TAG, "exitPrinterBuffer printResult: " + result); showToast(result + ""); /**48= Success *49= Missing paper or print hatch door open *50= Print hatch open *52= Print head overheating */ } }); Function: void exitPrinterBuffer(Boolean commit,PrintResultCallback callback) Remark:Exit transaction print mode and call back the result parameter: 1. commit –> true: exit the transaction after printing, false: exit the transaction directly 2. callback –> Result callback .. code-block:: java :linenos: :emphasize-lines: 5 mIminPrintUtils.exitPrinterBuffer(true, new PrintResultCallback() { @Override public void printResult(int result) { Log.d(TAG, "exitPrinterBuffer printResult: " + result); showToast(result + ""); /**48= Success *49= Missing paper or print hatch door open *50= Print hatch open *52= Print head overheating */ } }); 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 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.