public interface PrinterDevice extends Device, TimeConstants
PrinterDevice
interface defines the APIs for interacting with a printer device in applications.
This interface is used to perform various printing operations, including text, images, and barcodes.
Obtaining the Printer Device Instance:
PrinterDevice printerDevice = (PrinterDevice) POSTerminal.getInstance().getDevice("com.cloudpos.device.printer");
The identifier "com.cloudpos.device.printer" is used to uniquely identify the printer device, as specified by the implementation.
Functionalities:
Permissions:
Applications need to request permission to access the printer device:
<uses-permission android:name="android.permission.CLOUDPOS_PRINTER"/>
Note: It is recommended to check the printer's battery level before initiating a print operation. Avoid printing if the battery level is below 5% to prevent data loss.
Device
Modifier and Type | Field and Description |
---|---|
static int |
BARCODE_CODABAR
Constant for CODABAR barcode format.
|
static int |
BARCODE_CODE128
Constant for CODE128 barcode format.
|
static int |
BARCODE_CODE39
Constant for CODE39 barcode format.
|
static int |
BARCODE_CODE93
Constant for CODE93 barcode format.
|
static int |
BARCODE_HRI_POS_ABOVE
HRI printed above the barcode.
|
static int |
BARCODE_HRI_POS_BELOW
HRI printed below the barcode.
|
static int |
BARCODE_HRI_POS_BOTH
HRI printed both above and below the barcode.
|
static int |
BARCODE_HRI_POS_NONE
HRI (Human Readable Interpretation) not printed with the barcode.
|
static int |
BARCODE_ITF
Constant for ITF (Interleaved Two of Five) barcode format.
|
static int |
BARCODE_JAN13
Constant for JAN13 (EAN13) barcode format.
|
static int |
BARCODE_JAN8
Constant for JAN8 (EAN8) barcode format.
|
static int |
BARCODE_UPC_A
Constant for UPC-A barcode format.
|
static int |
BARCODE_UPC_E
Constant for UPC-E barcode format.
|
static int |
PDF_ALL_PAGE
Constant representing all pages, typically used in PDF printing.
|
static int |
STATUS_OUT_OF_PAPER
Printer status indicating out of paper.
|
static int |
STATUS_PAPER_EXIST
Printer status indicating paper is present.
|
FOREVER, IMMEDIATE, MilliSECOND, SECOND
Modifier and Type | Method and Description |
---|---|
android.graphics.Bitmap |
convertHTML2image(android.content.Context context,
java.lang.String htmlContent)
Synchronously converts HTML content into an image.
|
void |
convertHTML2image(android.content.Context context,
java.lang.String htmlContent,
PrinterHtmlListener listener)
Asynchronously converts HTML content into an image format.
|
android.graphics.Bitmap |
convertHTML2image(java.lang.String htmlContent)
Synchronously converts HTML content into an image.
|
void |
convertHTML2image(java.lang.String htmlContent,
PrinterHtmlListener listener)
Asynchronously converts HTML content into an image format.
|
void |
cutPaper()
Cuts the paper if the printer supports this feature.
|
Format |
getDefaultParameters()
Retrieves the default printing format and restores it in the printer.
|
void |
open(int logicalID)
Initializes and opens the printer device for use.
|
void |
printBarcode(Format format,
int barcodeType,
java.lang.String barcode)
Prints a barcode with specified formatting and type.
|
void |
printBitmap(android.graphics.Bitmap bitmap)
Prints a bitmap image.
|
void |
printBitmap(Format format,
android.graphics.Bitmap bitmap)
Prints a bitmap image with specified formatting.
|
void |
printBitmap(Format format,
android.graphics.Bitmap bitmap,
int brightness)
Prints a bitmap image with specified formatting and brightness adjustment.
|
void |
printBitmapAutoGrayscale(android.graphics.Bitmap bitmap)
Prints a bitmap image with automatic grayscale conversion.
|
void |
printBitmapAutoGrayscale(Format format,
android.graphics.Bitmap bitmap)
Prints a bitmap image with automatic grayscale conversion and specified formatting.
|
void |
printBitmapAutoGrayscale(Format format,
android.graphics.Bitmap bitmap,
int brightness)
Prints a grayscale image using a specified format and brightness.
|
void |
printHTML(android.content.Context context,
java.lang.String htmlContent)
Synchronously prints HTML content.
|
void |
printHTML(android.content.Context context,
java.lang.String htmlContent,
PrinterHtmlListener listener)
Asynchronously prints the specified HTML content.
|
void |
printHTML(java.lang.String htmlContent)
Synchronously prints HTML content.
|
void |
printHTML(java.lang.String htmlContent,
PrinterHtmlListener listener)
Asynchronously prints the specified HTML content.
|
void |
printlnText(Format format,
java.lang.String message)
Prints the provided text message on the printer with line wrapping, using the specified format.
|
void |
printlnText(java.lang.String message)
Prints the provided text message on the printer, followed by a line break.
|
void |
printPDF(java.io.InputStream pdf)
Prints content from a PDF.
|
void |
printPDF(java.io.InputStream pdf,
int pageNumber)
Prints specific pages of a PDF.
|
void |
printPDFWithBrightness(java.io.InputStream pdf,
int pageNumber,
int brightness)
Prints a PDF with specified brightness for black and white conversion.
|
void |
printText(Format format,
java.lang.String message)
Prints the provided text message on the printer using a specified format.
|
void |
printText(java.lang.String message)
Prints text on the printer.
|
byte[] |
queryESC(byte[] esc,
int length,
int timeout)
Queries the result of an ESC command.
|
int |
queryStatus()
Checks the paper status in the printer.
|
int |
queryVoltage(int[] capacity,
int[] voltage)
Queries the battery status of the printer.
|
void |
resetFormat()
Resets the printer to its default format settings.
|
int |
sendESCCommand(byte[] esc)
Sends an ESC (escape) command to the printer.
|
cancelRequest, close, getFailCount, getUsageCount, open
static final int BARCODE_UPC_A
static final int BARCODE_UPC_E
static final int BARCODE_JAN13
static final int BARCODE_JAN8
static final int BARCODE_CODE39
static final int BARCODE_ITF
static final int BARCODE_CODABAR
static final int BARCODE_CODE93
static final int BARCODE_CODE128
static final int BARCODE_HRI_POS_NONE
static final int BARCODE_HRI_POS_ABOVE
static final int BARCODE_HRI_POS_BELOW
static final int BARCODE_HRI_POS_BOTH
static final int STATUS_OUT_OF_PAPER
static final int STATUS_PAPER_EXIST
static final int PDF_ALL_PAGE
void open(int logicalID) throws DeviceException
logicalID
- The logical identifier of the printer device. This ID is used to select
the specific printer when multiple devices are available.DeviceException
- for standard reasons as documented in DeviceException
.void printText(java.lang.String message) throws DeviceException
message
- The text message to be printed.DeviceException
- for standard reasons as documented in DeviceException
.void printlnText(java.lang.String message) throws DeviceException
message
- The text message to be printed. The method will handle line wrapping
if the text exceeds the width of the printable area.DeviceException
- for standard reasons as documented in DeviceException
.void printText(Format format, java.lang.String message) throws DeviceException
Format
object. The specified format will be applied to the text message and
any subsequent print operations until a new format is set.format
- The Format
object that specifies the desired text formatting.
Refer to the Format
class for available formatting options.message
- The text message to be printed. The method will apply the specified format
to this text during printing.DeviceException
- for standard reasons as documented in DeviceException
.void printlnText(Format format, java.lang.String message) throws DeviceException
Format
object. After printing the message, it automatically moves to the next line.
The printer will apply the given format not only to this text message but also to subsequent print operations until a new format is set. This allows for consistent styling across multiple lines of text.
format
- The Format
object specifying the text formatting. Refer to Format
for
available formatting options.message
- The string message to be printed. The printer will apply line wrapping if the text exceeds
the printable area width.DeviceException
- for standard reasons as documented in DeviceException
.void printBitmap(android.graphics.Bitmap bitmap) throws DeviceException
bitmap
- The bitmap image to be printed.DeviceException
- for standard reasons as documented in DeviceException
.void printBitmap(Format format, android.graphics.Bitmap bitmap, int brightness) throws DeviceException
format
- The Format
object specifying the bitmap's formatting. See Format
for options.bitmap
- The Bitmap
image to be printed.brightness
- Brightness threshold for image conversion (128 to 255 recommended). Higher values result in lighter prints.DeviceException
- For standard error scenarios. See DeviceException
for more information.void printBitmapAutoGrayscale(android.graphics.Bitmap bitmap) throws DeviceException
bitmap
- The Bitmap
image to be printed in grayscale.DeviceException
- For standard error scenarios. See DeviceException
for more information.void printBitmap(Format format, android.graphics.Bitmap bitmap) throws DeviceException
format
- The Format
object specifying the bitmap's formatting. See Format
for options.bitmap
- The Bitmap
image to be printed.DeviceException
- For standard error scenarios. See DeviceException
for more information.void printBitmapAutoGrayscale(Format format, android.graphics.Bitmap bitmap) throws DeviceException
format
- The Format
object specifying the bitmap's formatting. See Format
for options.bitmap
- The Bitmap
image to be printed in grayscale.DeviceException
- For standard error scenarios. See DeviceException
for more information.void printBitmapAutoGrayscale(Format format, android.graphics.Bitmap bitmap, int brightness) throws DeviceException
This method allows printing a bitmap image in grayscale by configuring the print format. The printer will use the provided format settings for printing.
format
- The Format
object specifying the bitmap's formatting. See Format
for options.bitmap
- The Bitmap
image to be printed in grayscale.brightness
- Brightness threshold for image conversion (128 to 255 recommended). Higher values result in lighter prints.DeviceException
- For standard error scenarios. See DeviceException
for more information.void printBarcode(Format format, int barcodeType, java.lang.String barcode) throws DeviceException
format
- The Format
object specifying the barcode's formatting. See Format
for options.barcodeType
- The type of barcode to print, as defined by constant values.barcode
- The content of the barcode to be printed.DeviceException
- For standard error scenarios. See DeviceException
for more information.int sendESCCommand(byte[] esc) throws DeviceException
Use manufacturer-provided command formats for specific operations.
esc
- The ESC command data.DeviceException
- for standard errors, detailed in DeviceException
.void cutPaper() throws DeviceException
DeviceException
- for standard errors, detailed in DeviceException
.int queryStatus() throws DeviceException
0
for out of paper, 1
for normal, negative values for abnormal status.DeviceException
- for standard errors, detailed in DeviceException
.Format getDefaultParameters() throws DeviceException
DeviceException
- for standard errors, detailed in DeviceException
.byte[] queryESC(byte[] esc, int length, int timeout) throws DeviceException
esc
- The ESC command.length
- The expected return length.timeout
- The time limit for the query.DeviceException
- for standard errors, detailed in DeviceException
.void printHTML(android.content.Context context, java.lang.String htmlContent, PrinterHtmlListener listener) throws DeviceException
This method triggers PrinterHtmlListener.onFinishPrinting(int)
upon completion and PrinterHtmlListener.onGet(Bitmap,int)
to retrieve the printed image.
context
- The Android context where this method is called.htmlContent
- HTML content to be printed.listener
- Listener to handle print callbacks.DeviceException
- for errors, as detailed in DeviceException
.void convertHTML2image(android.content.Context context, java.lang.String htmlContent, PrinterHtmlListener listener) throws DeviceException
This method triggers PrinterHtmlListener.onGet(Bitmap,int)
to obtain the converted image.
context
- The Android context of invocation.htmlContent
- HTML content to be converted.listener
- Listener for image conversion callbacks.DeviceException
- for errors, as specified in DeviceException
.void printHTML(java.lang.String htmlContent, PrinterHtmlListener listener) throws DeviceException
This method triggers PrinterHtmlListener.onFinishPrinting(int)
upon completion and PrinterHtmlListener.onGet(Bitmap,int)
to retrieve the printed image.
htmlContent
- HTML content to be printed.listener
- Listener to handle print callbacks.DeviceException
- for errors, as detailed in DeviceException
.void convertHTML2image(java.lang.String htmlContent, PrinterHtmlListener listener) throws DeviceException
This method triggers PrinterHtmlListener.onGet(Bitmap,int)
to obtain the converted image.
htmlContent
- HTML content to be converted.listener
- Listener for image conversion callbacks.DeviceException
- for errors, as specified in DeviceException
.void printHTML(android.content.Context context, java.lang.String htmlContent) throws DeviceException
Note: This method is synchronous. Avoid calling it on the Main UI thread as it may take time to render the WebView image.
context
- The context where the method is called.htmlContent
- HTML content to print.DeviceException
- for documented standard errors, see DeviceException
.android.graphics.Bitmap convertHTML2image(android.content.Context context, java.lang.String htmlContent) throws DeviceException
Note: As this method is synchronous, avoid calling it on the Main UI thread to prevent delays due to WebView rendering.
context
- The context from which this method is invoked.htmlContent
- HTML content to be converted into an image.DeviceException
- for errors as defined in DeviceException
.void printHTML(java.lang.String htmlContent) throws DeviceException
Note: This method is synchronous. Avoid calling it on the Main UI thread as it may take time to render the WebView image.
htmlContent
- HTML content to print.DeviceException
- for documented standard errors, see DeviceException
.android.graphics.Bitmap convertHTML2image(java.lang.String htmlContent) throws DeviceException
Note: As this method is synchronous, avoid calling it on the Main UI thread to prevent delays due to WebView rendering.
htmlContent
- HTML content to be converted into an image.DeviceException
- for errors as defined in DeviceException
.int queryVoltage(int[] capacity, int[] voltage) throws DeviceException
capacity
- An array to store battery capacity. int[1]voltage
- An array to store battery voltage.int[1]DeviceException
- for standard errors, detailed in DeviceException
.void printPDF(java.io.InputStream pdf) throws DeviceException
pdf
- The InputStream of the PDF.DeviceException
- for standard errors, detailed in DeviceException
.void printPDF(java.io.InputStream pdf, int pageNumber) throws DeviceException
pdf
- The InputStream of the PDF.pageNumber
- Specify the page numbers to print, or if less than total pages, print as specified.DeviceException
- for standard errors, detailed in DeviceException
.void printPDFWithBrightness(java.io.InputStream pdf, int pageNumber, int brightness) throws DeviceException
pdf
- The InputStream of the PDF.pageNumber
- Specify the page numbers to print. If less than the total number of pages, only specified pages are printed.brightness
- Defines the threshold for converting colors to black and white. Higher values result in lighter prints. Recommended range: 128 to 255.DeviceException
- for standard errors, detailed in DeviceException
.void resetFormat() throws DeviceException
DeviceException
- for standard errors, detailed in DeviceException
.