Skip to content

Printer

com.brother.ptouch.sdk.Printer class provides APIs to print data or get information from the printer.

Instance Methods

setPrinterInfo

Set PrinterInfo object to specify the printer and print settings.

Declaration

boolean setPrinterInfo(PrinterInfo printerInfo);

Parameters

Parameter Description
printerInfo Printer and print setting information.

Return Value

Always true.

getPrinterInfo

Get the printer information which is currently set.

Declaration

PrinterInfo getPrinterInfo();

Return Value

Current PrinterInfo object.

setBluetooth

Set the Bluetooth adapter which is required to communicate with printer via Bluetooth.

Declaration

void setBluetooth(BluetoothAdapter bluetoothAdapter);

Parameters

Parameter Description
bluetoothAdapter Bluetooth adapter of Android SDK.

startCommunication

Open a session to communicate with the printer based on the connection type. You need to call it before calling any API communicating with the printer. You need to call endCommunication when it becomes unnecessary.

Declaration

boolean startCommunication();

Return Value

true if success, otherwise false.

endCommunication

Close the session opened via startCommunication

Declaration

boolean endCommunication();

Return Value

Always true.

printImage

Print the image using print settings set by setPrinterInfo.

Declaration

PrinterStatus printImage(Bitmap bmp);

Parameters

Parameter Description
bmp Bitmap object to be printed.

Return Value

PrinterStatus object as the result.

printFile

Print the image file or print data file (.prn) using print settings set by setPrinterInfo.

Declaration

PrinterStatus printFile(String filepath);

Parameters

Parameter Description
filepath The image (.jpg/.jpeg, .bmp, .png) file path or print data (.prn) path to be printed.

Return Value

PrinterStatus object as the result.

printFileList

Print the image files using print settings set by setPrinterInfo.

Declaration

PrinterStatus printFileList(List<String> fileList);

Parameters

Parameter Description
fileList The image file (.jpg/.jpeg, .bmp, .png) path list to be printed.

Return Value

PrinterStatus object as the result.

printPdfFile

Print the pdf file using print settings set by setPrinterInfo. Available on Android 5.0 or later.

Declaration

PrinterStatus printPdfFile(String filepath, int pagenum);

Parameters

Parameter Description
filepath The PDF file path to be printed.
pagenum The page number.

Return Value

PrinterStatus object as the result.

getPDFFilePages

Get the page count of the specified pdf file. Available on Android 5.0 or later.

Declaration

int getPDFFilePages(String filepath);

Parameters

Parameter Description
filepath The PDF file path.

Return Value

The page count.

printPdf

Same functionality as printPdfFile. Available on less than Android 6.0.

Declaration

PrinterStatus printPdf(String filepath, int pagenum);

Parameters

Parameter Description
filepath The PDF file path to be printed.
pagenum The page number.

Return Value

PrinterStatus object as the result.

getPDFPages

Same functionality as getPDFFilePages. Available on less than Android 6.0.

Declaration

int getPDFPages(String filepath);

Parameters

Parameter Description
filepath The PDF file path.

Return Value

The page count.

cancel

Cancel printing. Invalid while sending data.

Declaration

boolean cancel();

Return Value

Always true.

getPrinterStatus

Retrieves the printer status.

Declaration

PrinterStatus getPrinterStatus();

getFirmVersion

Get the firmware version of the specified printer as a string.

Declaration

String getFirmVersion();

Return Value For example, "0102". This means "ver.1.02".

getLabelParam

Get the detail information of the media (for QL, PT, TD and RJ series) specified by setPrinterInfo.

Declaration

LabelParam getLabelParam();

Return Value

The media information as LabelParam.

getLabelInfo

Retrieves the label information from the printer. Available for QL and PT series only.

Declaration

LabelInfo getLabelInfo();

Return Value

The label information as LabelInfo.

getBatteryInfo

Retrieves the battery information of the printer.

Declaration

BatteryInfo getBatteryInfo();

Return Value

The battery information as BatteryInfo.

getSystemReport

Retrieves the system report of the printer like self-print contents. Available if port is other than Port.NET.

Declaration

String getSystemReport;

Return Value

The system report.

setMessageHandle

Set a message handler to the SDK to receive the message from it.

Declaration

void setMessageHandle(Handler handler, int MsgType);

Parameters

Parameter Description
handler Message handler.
MsgType Identifies the messages.

sendBinaryFile

Send the binary file containing the command. Since the status check is not performed, it is sent even if the printer specified by printerModel is different from the actually connected printer.

Warning

If you pass a file including raster commands customized by yourself, automatic status notification mode must be turned off (Do not notify). The notifications from printers are not received in this function. For information on the mode, see a command reference for your printer.

Declaration

PrinterStatus sendBinaryFile(String filepath);

Parameters

Parameter Description
filepath File path to be sent.

Return Value

PrinterStatus object as the result.

sendBinary

Send the binary data containing the command. Since the status check is not performed, it is sent even if the printer specified by printerModel is different from the actually connected printer.

Declaration

PrinterStatus sendBinary(byte[] data)

Parameters

Parameter Description
data Data to be sent.

Return Value

PrinterStatus object as the result.

sendDatabase

Send the database data described in .csv format. In addition, this updates the database for printers that have templates and databases created and linked by P-touch Editor.

.csv data format restrictions :

  • the delimiter is ,(comma) only
  • Alphanumeric & symbol in ASCII only

Declaration

 PrinterStatus sendDatabase(String filepath)

Parameters

Parameter Description
filepath The path of the .csv file.

Return Value

PrinterStatus object as the result.

startPTTPrint

Start creating the command and print data string for a P-touch Template. Specify a template and the character encoding. This function assumes the default P-touch Template settings. Your application may not be able to print if the printer's settings differ from the defaults. If necessary, use the P-touch Template Setting Tool to configure the printer.

Declaration

boolean startPTTPrint(int key, String encode);

Parameters

Parameter Description
key Key number assigned to the template. The key starts from 1.
encode "SJIS" for printer models with Japanese fonts, "GB18030" for printer models with Chinese fonts or null for all other printer models.

Return Value

false if the key is out of range or the printer doesn't support P-touch template, otherwise true.

replaceText

Replaces the next replaceable text in a P-touch Template. Text strings are replaced in order of small object number.

Declaration

boolean replaceText(String data);

Parameters

Parameter Description
data Replacement text.

Return Value

false if the printer doesn't support P-touch template, otherwise true.

replaceTextIndex

Replaces the text in an object of a P-touch Template, specified by its object number.

Declaration

boolean replaceTextIndex(String data, int index);

Parameters

Parameter Description
data Replacement text.
index Object number in which to replace the text. The range depends on models.

Return Value

false if the index is out of range or the printer doesn't support P-touch template, otherwise true.

replaceTextName

Replaces the text in an object of a P-touch Template, specified by the object's name.

Declaration

boolean replaceTextName(String data, String objectName);

Parameters

Parameter Description
data Replacement text.
objectName Object name of the object in which to replace the text.

Return Value

false if the data length longer than 20 or the printer doesn't support P-touch template, otherwise true.

flushPTTPrint

Transmits command and print data used to print a P-touch Template.

Declaration

PrinterStatus flushPTTPrint();

Return Value

PrinterStatus object as the result.

updateFirm

Send firmware files. For Bluetooth and USB transfers, use pdz files. For all interface, use blf files.

Declaration

public PrinterStatus updateFirm(String filepath)

Parameters

Parameter Description
filepath Template file path.

Return Value

PrinterStatus object as the result.

transfer

Transfers a P-touch Template file to the printer. The template file (*.pdz, *.blf) is created by P-touch Transfer Manager, a Windows application. For Bluetooth and USB transfers, use pdz files. For all interface, use blf files.

Declaration

PrinterStatus transfer(String filepath);

Parameters

Parameter Description
filepath Template file path.

Return Value

PrinterStatus object as the result.

removeTemplate

Removes templates from the printer.

Declaration

PrinterStatus removeTemplate(List<Integer> keyList);

Parameters

Parameter Description
keyList List of template IDs to be removed.

Return Value

PrinterStatus object as the result.

getTemplateList

Gets a list of the templates that have been downloaded to the printer.

Declaration

PrinterStatus getTemplateList(List<TemplateInfo> tmplList);

Parameters

Parameter Description
tmplList List to hold the acquired template information.

Return Value

PrinterStatus object as the result. The PrinterStatus.ErrorCode is set to ERROR_TEMPLATE_NOT_EXIST if there are no templates on the printer.

getNetPrinters

Discover printers of the given model that are connected to the same network.

Declaration

NetPrinter[] getNetPrinters(String modelName);

Parameters

Parameter Description
modelName Printer model name.

Return Value

Array of discovered NetPrinter.

getNetPrinters

Discover printers of the given models that are connected to the same network.

Declaration

NetPrinter[] getNetPrinters(String modelName[]);

Parameters

Parameter Description
modelName Array of printer model name.

Return Value

Array of discovered NetPrinter.

getBLEPrinters

Discover printers which are connectable via Bluetooth Low Energy. Available on Android 5.0 or later.

Declaration

List<BLEPrinter> getBLEPrinters(BluetoothAdapter adapter, long timeout);

Parameters

Parameter Description
adapter Bluetooth adapter of Android SDK
timeout Discovery time in mili second

Return Value

Array of discovered BLEPrinter.

getUsbDevice

Gets a connected USB device.

Declaration

UsbDevice getUsbDevice(UsbManager usbManager);

Parameters

Parameter Description
usbManager android.hardware.usb.UsbManager

Return Value

Connected Brother UsbDevice. null if no supported Brother printer is connected.

updatePrinterSettings

Update printer settings. See Printer Configurations for available values. Some settings are not applied until the printer is restarted. Restart the printer, then confirm the values are properly applied via getPrinterSettings after the restart.

Declaration

PrinterStatus updatePrinterSettings(Map<PrinterSettingItem, String> settings)

Parameters

Parameter Description
settings Setting keys and values

Return Value

PrinterStatus object as the result.

getPrinterSettings

Get printer settings. See Printer Configurations for available values.

Declaration

PrinterStatus getPrinterSettings(ArrayList<PrinterSettingItem> keys, Map< PrinterSettingItem,String> values);

Parameters

Parameter Description
keys Index of settings.
values Output argument the SDK stores the result. Need to be inistantiated by the caller.

Return Value

PrinterStatus object as the result.

updateBluetoothPreference

Updates Bluetooth settings of the MW series. Refer to BluetoothPreference. This method does not check if the request has been reflected on the device. Please check using getBluetoothPreference if needed.

Declaration

PrinterStatus updateBluetoothPreference(BluetoothPreference btPre);

Parameters

Parameter Description
btPre Bluetooth settings

Return Value

PrinterStatus object as the result.

getBluetoothPreference

Gets Bluetooth settings from the MW series. Refer to BluetoothPreference.

Declaration

PrinterStatus getBluetoothPreference(BluetoothPreference btPre);

Parameters

Parameter Description
btPre Output argument the SDK stores the result. Need to be instantiated by the caller.

Return Value

PrinterStatus object as the result.

setPrinterModelFromStatus

Set PrinterModel from PrinterStatus instead of from PrinterInfo.

It is used when the model name cannot be determined by the search API, such as TD-2350D.

Declaration

void setPrinterModelFromStatus(PrinterStatus status)

Parameters

Parameter Description
status Status returned by getPrinterStatus

Notes

Template Object Number Range

Object Number Range Printer Model
1 - 50 MW series, PT-P9xx, QL series
1 - 200 PJ-663
1 - 99 TD series, RJ series
1 - 255 PJ-7xx