Skip to content

PAL

Overview

The SynqpayPrinter module integrates with the built-in thermal printer on Synqpay devices, allowing developers to create structured print jobs using the Printer Abstraction Layer (PAL).


Printing API

void print(in Bundle bundle);
The print method accepts a Bundle object representing the document to be printed. The Bundle is constructed using the SynqpayPAL package.


Printer Abstraction Layer (PAL)

The SynqpayPAL package provides the necessary tools for building structured, customizable printable documents. It offers options for adjusting text direction, alignment, and line customization.

SynqpayPAL class

Direction Enum

  • LTR: Left-to-right text direction (default).
  • RTL: Right-to-left text direction.

Align Enum

  • START: Aligns text to the left.
  • END: Aligns text to the right.
  • CENTER: Centers the text.

Key Defaults

  • Direction: Left-to-Right (LTR)
  • Alignment: Start
  • Text size: 14 (inherited from the line, but can be overridden for specific text)
  • Fill last: false
  • Vertical space: None

Key Methods

public static IDocument newDocument();
Creates a new document for printing.


IDocument Interface

The IDocument interface provides methods for constructing and finalizing a printable document.

Key Methods

IDocument direction(SynqpayPAL.Direction eDirection);
Sets the text flow direction.

ILine addLine();
Adds a new line to the document.

IDocument addSpace(int space);
Adds vertical space between elements (default: none).

IDocument addDivider(int height);
Adds a horizontal divider with specified thickness.

Bundle bundle();
Finalizes the document into a Bundle for printing.


ILine Interface

The ILine interface customizes the layout of text elements within a line.

Working Modes

  1. Regular Mode: Text elements are added sequentially without spacing. Alignment applies only to the entire line, not individual text elements.
  2. Fill Last Mode: The last text element stretches to fill the remaining space in the line. Alignment can only be adjusted for the last element.
  3. Weight Mode: Space allocation is proportional to the weight of text elements. The fillLast property is ignored. Alignment can be applied to all text elements because they occupy distinct spaces.

Key Methods

IText addText();
Adds a text element to the line.

ILine align(SynqpayPAL.Align align);
Sets the alignment for the entire line (not individual text elements).

ILine textSize(int size);
Sets the text size for all elements in the line (default: 14). Inherited by text elements but can be overridden for specific text.

ILine fillLast(boolean fill);
Enables the Fill Last Mode.

ILine spaceTop(int spaceTop);
Adds space above the line (default: none).

ILine spaceBottom(int spaceBottom);
Adds space below the line (default: none).


IText Interface

The IText interface customizes the appearance and styling of text elements.

Key Methods

IText text(String text);
Sets the text content.

IText bold(boolean bold);
Applies bold styling to the text.

IText italic(boolean italic);
Applies italic styling to the text.

IText underline(boolean underline);
Underlines the text.

IText textSize(int size);
Sets the text size (default: inherited from the line, but can be overridden for specific text).

IText weight(int weight);
Defines the space allocation weight for Weight Mode.

IText align(SynqpayPAL.Align align);
Sets the alignment for the text element.


Example Usage

import android.os.Bundle;
import SynqpayPAL.*;

// Create a new document
IDocument document = SynqpayPAL.newDocument();

ILine line1 = document.addLine();
line1.addText()
        .text("Hello");
line1.addText().text("World!");

document.addSpace(30);

document.addLine().addText().text("Fill Last Mode").bold(true);
document.addDivider(4);
ILine line2 = document.addLine();
line2.fillLast(true);
line2.addText().text("Hello");
line2.addText().text("World").align(PAL.Align.END);

document.addSpace(30);

document.addLine().addText().text("Weight Mode").bold(true);
document.addDivider(4);
ILine line3 = document.addLine();
line3.addText().text("Hello").weight(1);
line3.addText().text("World").weight(1);
ILine line4 = document.addLine();
line4.addText().text("Another").weight(1);
line4.addText().text("Text of line").weight(1);

document.addSpace(10);

ILine line5 = document.addLine();
line5.addText().text("ITEM").weight(6);
line5.addText().text("QTY").weight(2);
line5.addText().text("PRICE").weight(3).align(PAL.Align.END);

ILine line6 = document.addLine();
line6.addText().text("Apples").weight(6);
line6.addText().text("1kg").weight(2);
line6.addText().text("$1.00").weight(3).align(PAL.Align.END);

ILine line7 = document.addLine();
line7.addText().text("Coca Cola 1,5l").weight(6);
line7.addText().text("3 pcs").weight(2);
line7.addText().text("$10.00").weight(3).align(PAL.Align.END);

ILine line8 = document.addLine();
line8.addText().text("Bread 1,5l").weight(6);
line8.addText().text("3 pcs").weight(2);
line8.addText().text("$10.00").weight(3).align(PAL.Align.END);


// Finalize and print
Bundle bundle = document.bundle();
try {
    printer.print(bundle);
} catch (RemoteException e) {
    throw new RuntimeException(e);
}
Operator menu
Example