Getnet DocsGetnet Docs

Printing Bitmaps

This guide demonstrates how to print images using the terminal’s thermal printer. The PeripheralsLib library allows you to send Bitmap objects directly to the printer.

Image Requirements

To ensure consistent printing results across different terminal models and avoid errors, adhere to the following image specifications:

  • Format: Bitmap (android.graphics.Bitmap)
  • Maximum Width: 390 pixels
  • Color Scheme: Black and White (1-bit depth recommended)
  • Compression: JPEG compression is recommended for the source asset.

Basic Printing

If you do not need to track the status of the print job, you can use the simple printBitmap method.

// Assuming 'manager' is an initialized instance of PeripheralsManager
Bitmap myImage = BitmapFactory.decodeResource(getResources(), R.drawable.my_receipt_image);

manager.printBitmap(myImage);

Printing with Callbacks

To handle success or failure scenarios (e.g., paper out, overheating), use the method that accepts a PrintBmpCallback. This is the recommended approach for production apps to provide user feedback.

Implementation

manager.printBitmap(myBitmap, new PrintBmpCallback() {
    @Override
    public void onSuccess() {
        // Called when printing completes successfully
        Log.d("Printer", "Print finished successfully");
        runOnUiThread(() -> Toast.makeText(context, "Print Complete", Toast.LENGTH_SHORT).show());
    }

    @Override
    public void onError(String error) {
        // Called if an error occurs during printing
        Log.e("Printer", "Print failed: " + error);
        runOnUiThread(() -> Toast.makeText(context, "Error: " + error, Toast.LENGTH_LONG).show());
    }
});

Callback Methods

MethodDescription
onSuccess()Triggered when the print job finishes without errors.
onError(String error)Triggered if the print job fails. The string contains the error description.