6. Printing
6.1 print()
pos.print(bitmap) { success, message ->
if (success) {
Toast.makeText(this,
"Printed successfully",
Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this,
"Print error: $message",
Toast.LENGTH_LONG).show()
}
}
pos.print(bitmap, (success, message) -> {
if (success) {
Toast.makeText(this,
"Printed successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,
"Print error: " + message,
Toast.LENGTH_LONG).show();
}
});
6.2 BitmapBuilder — Building Custom Receipt Bitmaps
val builder = BitmapBuilder(paperWidth = 384)
| Method signature | Description |
|---|---|
| addLogo(bitmap, width, height) | Centres a Bitmap logo at the top. |
| addCentered(text, textSize, bold) | Prints a single centred text line. |
| addLeft(text, textSize, bold) | Prints a left-aligned text line. |
| addRow(label, value) | Two-column key/value row. |
| addSeparator() | Prints a full-width dashed separator line. |
| addGap(px) | Adds vertical whitespace of px pixels. |
| addStatusBanner(text) | Prints a large bold status banner (e.g. APPROVED). |
| build() | Returns the assembled Bitmap. |
Custom Receipt Example
return BitmapBuilder(paperWidth = 384)
.addLogo(logoBitmap, 150, 150)
.addCentered("MY HOSPITAL", 19, true)
.addGap(10)
.addCentered("CUSTOMER RECEIPT", 23, true)
.addGap(20)
.addRow("TERMINAL ID:",
result.terminalId)
.addRow("TRAN REF:",
result.transactionRef)
.addStatusBanner(
"TRANSACTION SUCCESSFUL")
.build()
return new BitmapBuilder(384)
.addLogo(logoBitmap, 150, 150)
.addCentered("MY HOSPITAL", 19, true)
.addGap(10)
.addCentered("CUSTOMER RECEIPT", 23, true)
.addGap(20)
.addRow("TERMINAL ID:",
result.getTerminalId())
.addRow("TRAN REF:",
result.getTransactionRef())
.addStatusBanner(
"TRANSACTION SUCCESSFUL")
.build();
6.3 buildReceiptBitmap() — SDK Auto-generated Receipt
The SDK can generate a fully formatted receipt bitmap automatically from a TransactionResult. Use this when you do not need a custom receipt layout.
override fun onApproved(
result: TransactionResult) {
val bitmap =
pos.buildReceiptBitmap(this, result)
pos.print(bitmap) { ok, msg ->
Log.d(TAG,
"Print: ok=$ok msg=$msg")
}
}
@Override
public void onApproved(TransactionResult result) {
Bitmap bitmap =
pos.buildReceiptBitmap(this, result);
pos.print(bitmap, (ok, msg) ->
Log.d(TAG, "Print: ok=" + ok + " msg=" + msg));
}