The PrinterHandler is responsible for structuring the information that should be printed on the receipt.

Initializing the PrinterHandler object.

private val printerHandler by lazy {

         PrinterHandler(activity) {
            when (it.state) {
                DeviceState.PRINTER_SUCCESS -> {
                    Log.e("Printer", "success")
                }
                DeviceState.PRINTER_ERROR -> {
                    Log.e("Printer", "Error")

                }
                else -> {

                }
            }

        }
    }
Public Methods
onPrintReceiptModel(receiptModel : Bitmap) : Unit Unit Starts the receipt printing process. Takes a receiptModel parameter(i.e a bitmap of the content to be printed on the receipt). see CombBitmap

CombBitmap

The CombBitmap class is responsible for holding all the contents to be printed on the receipt. It also has a method CombBitmap#getCombBitmap() which is used to retrieve the Bitmap (i.e the contents to be printed on the receipt ) to be passed to the onPrintReceiptModel(receiptModel: Bitmap) method.

<aside> 💡 See CombBitmap for more details.

</aside>

Usage

private fun getReceiptContent(): Bitmap {
        val combBitmap = CombBitmap()

        val bitmap: Bitmap = getMyBitMap() // replace with bitmap icon
        combBitmap.addBitmap(bitmap)

        // Print bitmap image
        combBitmap.addBitmap(bitmap)

        //Print a center-aligned text
        combBitmap.addBitmap(
            GenerateBitmap.str2Bitmap(
                "Horizon Test Slip",
                50,
                GenerateBitmap.AlignEnum.CENTER,
                true,
                false
            )
        )
				
				//Print a separator line
				combBitmap.addBitmap(GenerateBitmap.generateLine(1)) 

				// Print two texts, one aligned to the left and the other to the right.
				combBitmap.addBitmap(GenerateBitmap.str2Bitmap("Terminal ID:", "123456", 26, true, false))
				
			// Print three texts, with alignment left, center, and right respectively.
			combBitmap.addBitmap(GenerateBitmap.str2Bitmap("Status", "Items", "Cost", 23, true, false))

		// print row gap
		combBitmap.addBitmap(GenerateBitmap.generateGap(60))

		// Add a logo
		combBitmap.addBitmap(
				GenerateBitmap.formatBitmap(bitmap,GenerateBitmap.AlignEnum.CENTER)
		)
		
		// Add a header
		combBitmap.addBitmap(
				GenerateBitmap.str2Bitmap(
							title, 
							textSize, 
							GenerateBitmap.AlignEnum.CENTER, 
							true, 
							false
				)
		)
        
		// Print asterisk separator
		combBitmap.addBitmap(
				GenerateBitmap.str2Bitmap(
					"*************************************",
	        textSize,
	        GenerateBitmap.AlignEnum.CENTER,
	        true,
	        false
				)     
	  )

  return combBitmap.combBitmap
   
}