Impressão
Métodos de impressão do PosPinpad. Use os overloads com PrintAttributes (preferidos). O parâmetro notifyComplete controla a propagação de onPrintCompleted() — use false nas instruções intermediárias de um mesmo comprovante e true apenas na última: onPrintCompleted é chamado para cada instrução que notifica.
fun print(text: String) // texto plano (legado)
fun printText(text: String, attributes: PrintAttributes, notifyComplete: Boolean = true)
fun printColumns(texts: List<String>, attributes: List<PrintAttributes>, notifyComplete: Boolean = true)
fun printImage(source: Any, width: Int, height: Int)
fun printImage(source: Any, width: Int, height: Int, attributes: PrintAttributes, notifyComplete: Boolean = true)
fun printBitmap(bitmap: Bitmap, notifyComplete: Boolean = true)
fun printQrCode(payload: String, align: Align = Align.CENTER, sizePx: Int = 200, notifyComplete: Boolean = true)
fun feedPaper(lines: Int, notifyComplete: Boolean = true)
fun feedStep(steps: Int, notifyComplete: Boolean = true)
Exemplo:
// Align e Typeface são do SDK (com.tupifintech.apossdk.sdk.api.model), não de android.graphics
posPinpad.printText("COMPROVANTE DE VENDA", PrintAttributes(align = Align.CENTER, typeface = Typeface.BOLD), notifyComplete = false)
posPinpad.printColumns(
listOf("Valor", "R$ 50,00"),
listOf(PrintAttributes(weight = 1), PrintAttributes(align = Align.RIGHT, weight = 1)),
notifyComplete = false
)
posPinpad.printQrCode(pixPayload, sizePx = 200, notifyComplete = false)
posPinpad.feedStep(1) // destaca a bobina; última instrução notifica onPrintCompleted
Se preferir o comprovante pronto, imprima result.slip com posPinpad.print(result.slip!!).
Eventos
| Callback | Quando ocorre |
|---|---|
onPrintCompleted() | Instrução concluída (só as chamadas com notifyComplete = true) |
onNoHasPaper() | Sem papel |
onNotifyPrinterError(code, msg) | Erro da impressora. Interprete code com PrinterErrorCode (veja Callbacks — Erros da impressora) |
Os callbacks de impressão não chegam na main thread: use runOnUiThread ou Dispatchers.Main antes de mexer na UI.
Veja PrintAttributes (Align/Typeface).