Printing
It is possible to use the thermal printer of the Point Smart devices to print bitmap images, DTE, or custom images based on patterns called Custom Tags.
Print Bitmap
To print bitmap images with the Point Smart printer, use the print function of the BitmapPrinter
class. Access is provided through the MPManager
object, as shown in the example below:
val bitmapPrinter = MPManager.bitmapPrinter
val imageToPrint: Bitmap = bitmap // Get the bitmap image that will be printed
bitmapPrinter.print(imageToPrint) { response ->
response.doIfSuccess { printResult ->
// Handle success
}.doIfError { error ->
// Handle error in the printing operation
final BitmapPrinter bitmapPrinter = MPManager.INSTANCE.getBitmapPrinter();
final Bitmap imageToPrint = bitmap // Get the bitmap image that will be printed
final Function1<MPResponse<String>, Unit> callback = (final MPResponse<String> response) -> {
if (response.getStatus() == ResponseStatus.SUCCESS) {
// Handle success
} else {
// Handle error in the printing operation
}
return Unit.INSTANCE;
};
bitmapPrinter.print(imageToPrint, callback);
Field | Description |
dataToPrint (Bitmap) | The bitmap image that will be printed. |
callback ((MPResponse<String>) -> Unit) | Request response feature that provides the result of the printing operation. The [MPResponse] includes the status, the error (if any), and the details in case of success, which contain a String representing the ID or status of the printing. |
Print Custom Tag and DTE
The print
function of the BitmapPrinter
class in our SDK can also be used to create custom prints or DTEs.
In the first case, the print is done based on a pattern called Custom Tag, which consists of sending a string with different control tags for subsequent interpretation by our system, resulting in a physical receipt.
In the case of the DTE, the print is done by sending a transaction .xml
as a parameter.
You can see below how to implement prints of Custom Tags and DTEs.
val bitmapPrinter = MPManager.bitmapPrinter
val customTagToPrint: String = "{br}{b}this is a test text{/s}" // If you need to print a DTE, replace the custom tag string with the xml
val paymentMethodName: String? = null // Optional parameter that allows printing the name of the payment method used in case you want to print an electronic receipt (DTE type 39,41). Default value: null.
val printPdf417InReceipt: Boolean? = null // Optional parameter that allows printing the pdf417 barcode (the stain) in case you want to print an electronic receipt (DTE type 39,41). Default value: null.
bitmapPrinter.print(customTagToPrint, paymentMethodName, printPdf417InReceipt) { response ->
response.doIfSuccess { printResult ->
// Handle the successful print
}.doIfError { error ->
// Handle the error in the print operation
final BitmapPrinter bitmapPrinter = MPManager.INSTANCE.getBitmapPrinter();
final String customTagToPrint = "{br}{b}this is a test text{/s}" // If you need to print a DTE, replace the custom tag string with the xml
@Nullable
final String paymentMethodName; // Optional parameter that allows printing the name of the payment method in case you want to print an electronic receipt (DTE type 39,41). Default value: null.
@Nullable
final Boolean printPdf417InReceipt; // Optional parameter that allows printing the pdf417 barcode (the stain) in case you want to print an electronic receipt (DTE type 39,41). Default value: null.
final Function1<MPResponse<String>, Unit> callback = (final MPResponse<String> response) -> {
if (response.getStatus() == ResponseStatus.SUCCESS) {
// Handle the successful print
} else {
// Handle the error in the print operation
}
return Unit.INSTANCE;
};
bitmapPrinter.print(customTagToPrint, paymentMethodName, printPdf417InReceipt, callback);