Printer SDK

Printer SDK

Introduction

The Printer SDK is a library designed to simplify the integration of receipt printing functionality into Android applications. This SDK is for printing receipt information for Dejavoo Gateway-powered P series terminals.

Integrating the Printer SDK

This guide details the steps to integrate the Printer SDK into your Android project.

Prerequisites

Here are the prerequisites required to integrate the Printer SDK into your Android project.

  • Your Android project

  • Printer SDK kit

Supported Devices: Only Kozen device models are supported.

Font Size: The font size is controlled by the printer SDK, and there’s currently no option to change it. If customization is needed, an option will need to be implemented.

Supported Tags and Attributes for Printer: Only a few standard HTML tags are supported, such as <L>, <R>, <B>, <C>, <T>, and <img>.

Width Attribute: The <printer width="24"> attribute sets the paper width, allowing up to 24 characters per line. By default, the width is set to 24.

Downloading the Printer SDK

  1. Locate the printer_v3.0.aar file file provided with your Printer SDK kit.

  2. Copy the printer_v3.0.aar file file to your project directory.

Configuring Gradle Dependencies

  1. Open your project's build.gradle file (located at the module level).

  2. Add the following dependencies within the dependencies block:

implementation files "libs/printer_v3.0.aar"

Synchronizing Gradle

Click Sync Project with Gradle Files in Android Studio. This process updates your project with the Printer SDK and any additional dependencies you've included.

Accessing the Printer

Follow the steps mentioned below to access the printer:

  1. Place the provided .aar file into the lib folder of your project.

  2. In the app level build.gradle file, add the following line:

implementation files'libs/printer_v3.0.aar'

The printer_v3.0.aar file is provided with the kit. Download from here

  1. Use the following code to initialize the printer. After initialization, set the provided callbacks to handle responses for print completion or failure.
private IntentPrintApplication intentPrintApplication = new IntentPrintApplication(this);
 
intentPrintApplication.setLaunchInterface(new PrintLauncherInterface() {
   @Override
   public void onPrintSuccess(PrintResult printResult) {
       Log.e("printer", "onPrintSuccess");
 
   }
 
   @Override
   public void onPrintFailed(PrintErrorResult errorResult) {
       Log.e("printer", "onPrintFailed");
 
   }
});
  1. Use the code below to launch the printer with the provided printer data.
intentPrintApplication.launchPrinter(request);
  1. The format of the printer input should follow the structure shown below:

The request should contain: <request><printer width=\"24\"> </printer></request> tags.

Below is a sample request:

String request = "<request><printer width=\"24\">\n<C>Happy Restaurant</C><L>10/05/23</L><R>04:07</R><C>Thank you</C><B><C>MERCHANT COPY</C></B><IMG></IMG> </printer></request>";

Image data must be sent in an img tag, and it should be a base64-encoded string of the image.

Response tags

PrintResult (a model class for success response)

Response CodeResponse Message
printStatus SUCCESS
printMessage Print successful

PrintErrorResult (a model class for failure response)

Response CodeResponse Message
errorCode print failure code
errorMessage printer failure reason
errorException If any unknown exceptions while printing
Error codeError message
-1 Invalid printer data
-2 Unknown exception while printing
-3 Invalid printer data body
-4 No paper roll
-5 If any unknown exceptions while printing
-6 Printer data limit exceeded
Other error codes Printing failed