Class PrinterDevice
java.lang.Object
jp.co.sanei_elec.printerlibrary.api.PrinterDevice
-
Constructor Summary
ConstructorsConstructorDescriptionPrinterDevice
(android.content.Context context) PrinterDevice
(android.content.Context context, android.bluetooth.BluetoothAdapter adapter) -
Method Summary
Modifier and TypeMethodDescriptionvoid
connectPrinter
(android.bluetooth.BluetoothDevice device) Connects to Bluetooth printer.void
connectPrinter
(android.hardware.usb.UsbDevice device) Connects to USB printer.void
connectPrinter
(String host, int port) Connects to Network printer.void
connectPrinter
(AbstractConnector connector) Connect to printer.void
Disconnect printer.android.bluetooth.BluetoothDevice[]
discoverBlePrinter
(int timeoutMillis) Discover paired Bluetooth Low Energy printers.android.bluetooth.BluetoothDevice[]
discoverBthPrinter
(int timeoutMillis) Discover paired Bluetooth printers.android.hardware.usb.UsbDevice[]
discoverUsbPrinter
(int timeoutMillis) Discover attached USB printers.void
Ends page mode after page memory batch printing.Get printer connector object.Check printer status.getStatus
(int timeoutMillis) Check printer status.void
Initialize printed with default settings.int
inputRawData
(byte[] input, int timeoutMillis) Gets the binary data read on byte array from the printer port.int
inputRawData
(byte[] input, int offset, int length, int timeoutMillis) Gets the binary data read on byte array from the printer port.int
inputRawData
(int timeoutMillis) Gets the next byte from the printer port.boolean
Checks the currently connected printer port.static boolean
isSupportedPrinterDevice
(android.bluetooth.BluetoothDevice device) Check when Bluetooth device is recognize as supported printer device.static boolean
isSupportedPrinterDevice
(android.hardware.usb.UsbDevice device) Check when USB device is recognize as supported printer device.void
lineFeed
(int lines) Executes the linefeed with specified number of lines.void
outputRawData
(byte[] output) Sends the binary data on byte array to the printer port.void
outputRawData
(byte[] output, int offset, int length) Sends the binary data on byte array to the printer port.void
outputRawData
(int b) Sends the byte to the printer port.void
paperFeed
(int lines) Feeds forward/back the paper based on specified dot pitch.void
printBarcode
(BarcodeSystem barcodeSystem, byte[] barcode) Prints 1D barcode.void
printBarcode
(BarcodeSystem barcodeSystem, String barcode) Prints 1D barcode.void
printBitmap
(int[] argb, int width, int height, HorizontalAlignment align, boolean dither) void
printBitmap
(android.graphics.Bitmap bitmap) Prints bitmap image.void
printBitmap
(android.graphics.Bitmap bitmap, HorizontalAlignment align, boolean dither) Prints bitmap image.void
printBitmapRaster
(int[] argb, int width, int height, HorizontalAlignment align, boolean dither, boolean crop) void
printPDF417
(boolean truncate, boolean binaryEncode, int eccLevel, int size, byte[] barcode) Prints PDF417.void
printPDF417
(boolean truncate, boolean binaryEncode, int eccLevel, int size, String barcode) Prints PDF417.void
printQR
(int size, int eccLevel, byte[] barcode) Prints QR code.void
Prints QR code.void
printString
(String data) Specifies the strings and prints it with printer font.void
printString
(String data, String charsetName) Specifies the strings and prints it with printer font.void
printStringAndroidFont
(String text, int x, int y, android.graphics.Paint paint) Converts the strings on Android font to Raster image and prints it.void
setAlignment
(HorizontalAlignment alignment) Align the printing data at specified position.void
setBarcodeModification
(HRI hri, int width, int height) Sets attribute parameters for 1D barcode.void
setCodePage
(CodePage codePage) Sets a code page character.void
setDebug
(boolean on) Turn on debug information.void
setFontColor
(boolean reverse) Set font color.void
setFontMagnification
(int horizontalRation, int verticalRatio) Set character font magnification.void
setFontSmoothing
(boolean on) Set or cancel font smoothing.void
setFontStyle
(boolean bold, boolean italic, boolean underline) Set character font style.void
setFontStyle
(boolean bold, boolean italic, boolean underline, int dotPitch) Set character font style.void
setFontType
(boolean compact) Set character font type.void
setInternationalChar
(InternationalCharset internationalCharset) Sets an international character.void
setPageAttribute
(int x, int y, int width, int height) Sets attribute parameters for page mode.void
setPageAttribute
(int x, int y, int width, int height, PageDirection direction) Sets attribute parameters for page mode.void
setPageAttribute
(PageDirection direction) Sets attribute parameters for page mode.void
Set printer listener.void
Starts page mode.
-
Constructor Details
-
PrinterDevice
public PrinterDevice(android.content.Context context) -
PrinterDevice
public PrinterDevice(android.content.Context context, android.bluetooth.BluetoothAdapter adapter)
-
-
Method Details
-
isSupportedPrinterDevice
public static boolean isSupportedPrinterDevice(android.hardware.usb.UsbDevice device) Check when USB device is recognize as supported printer device.- Parameters:
device
- UsbDevice instance.- Returns:
- true if device is supported, otherwise return false.
-
isSupportedPrinterDevice
public static boolean isSupportedPrinterDevice(android.bluetooth.BluetoothDevice device) Check when Bluetooth device is recognize as supported printer device.- Parameters:
device
- BluetoothDevice instance.- Returns:
- true if device is supported, otherwise return false.
-
setDebug
public void setDebug(boolean on) Turn on debug information.- Parameters:
on
-true
turn on the debug,false
turned it off.
-
setPrinterListener
Set printer listener.- Parameters:
l
- the listener.
-
discoverUsbPrinter
public android.hardware.usb.UsbDevice[] discoverUsbPrinter(int timeoutMillis) Discover attached USB printers.- Parameters:
timeoutMillis
- time to wait for USB printer.- Returns:
- array of USB printers.
-
discoverBthPrinter
public android.bluetooth.BluetoothDevice[] discoverBthPrinter(int timeoutMillis) Discover paired Bluetooth printers.- Parameters:
timeoutMillis
- time to wait for Bluetooth printer.- Returns:
- array of Bluetooth printers.
-
discoverBlePrinter
public android.bluetooth.BluetoothDevice[] discoverBlePrinter(int timeoutMillis) Discover paired Bluetooth Low Energy printers.- Parameters:
timeoutMillis
- time to wait for Bluetooth printer.- Returns:
- array of Bluetooth printers.
-
connectPrinter
Connect to printer.- Parameters:
connector
- the connector instance.- Throws:
IOException
- if an I/O error occurs.
-
connectPrinter
Connects to Bluetooth printer.- Parameters:
device
- Bluetooth device.- Throws:
IOException
- if an I/O error occurs.
-
connectPrinter
Connects to USB printer.- Parameters:
device
- USB device.- Throws:
IOException
- if an I/O error occurs.
-
connectPrinter
Connects to Network printer.- Parameters:
host
- printer network address.port
- printer port.- Throws:
IOException
- if an I/O error occurs.
-
disconnectPrinter
public void disconnectPrinter()Disconnect printer. -
getConnector
Get printer connector object.- Returns:
- connector object.
-
isPrinterConnected
public boolean isPrinterConnected()Checks the currently connected printer port.- Returns:
true
if printer is connected, otherwise returnfalse
.
-
initPrinter
Initialize printed with default settings.- Throws:
IOException
- if an I/O error occurs.
-
printString
Specifies the strings and prints it with printer font.- Parameters:
data
- Specify the string which is convert to byte array using 'Shift-JIS' charset name.- Throws:
IOException
- if an I/O error occurs.
-
printString
Specifies the strings and prints it with printer font.- Parameters:
data
- the data string to print.charsetName
- the charset used to convert string.- Throws:
IOException
- if an I/O error occurs.
-
setFontType
Set character font type.- Parameters:
compact
- specify small font size.- Throws:
IOException
- if an I/O error occurs.
-
setFontStyle
Set character font style.- Parameters:
bold
- bold character.italic
- italic character.underline
- underline character.- Throws:
IOException
- if an I/O error occurs.
-
setFontStyle
public void setFontStyle(boolean bold, boolean italic, boolean underline, int dotPitch) throws IOException Set character font style.- Parameters:
bold
- bold character.italic
- italic character.underline
- underline character.dotPitch
- underline dot pitch.- Throws:
IOException
- if an I/O error occurs.
-
setFontMagnification
Set character font magnification.- Parameters:
horizontalRation
- horizontal direction magnification ratio, value from 1 to 8.verticalRatio
- vertical direction magnification ratio, value from 1 to 8.- Throws:
IOException
- if an I/O error occurs.
-
setFontColor
Set font color.- Parameters:
reverse
- specify black and white reverse character.- Throws:
IOException
- if an I/O error occurs.
-
setFontSmoothing
Set or cancel font smoothing.- Parameters:
on
- specify font smoothing.- Throws:
IOException
- if an I/O error occurs.
-
setAlignment
Align the printing data at specified position.- Parameters:
alignment
- the printing alignment.- Throws:
IOException
- if an I/O error occurs.
-
setCodePage
Sets a code page character.- Parameters:
codePage
- character code page.- Throws:
IOException
- if an I/O error occurs.
-
setInternationalChar
Sets an international character.- Parameters:
internationalCharset
- international charset of country.- Throws:
IOException
- if an I/O error occurs.
-
setBarcodeModification
Sets attribute parameters for 1D barcode.- Parameters:
hri
- printing position of the HRI characters at barcode printing.width
- the barcode width, value between 1 and 4.height
- the barcode height in dot pitch value between 1 and 255.- Throws:
IOException
- if an I/O error occurs.
-
printBarcode
Prints 1D barcode.- Parameters:
barcodeSystem
- barcode system.barcode
- barcode data.- Throws:
IOException
- if an I/O error occurs.
-
printBarcode
Prints 1D barcode.- Parameters:
barcodeSystem
- barcode system.barcode
- barcode data.- Throws:
IOException
- if an I/O error occurs.
-
printQR
Prints QR code.- Parameters:
size
- barcode symbol size, value between 1 and 40.eccLevel
- error control Level, value between 1 and 4.- L (7%)
- M (15%)
- Q (25%)
- H (30%)
barcode
- barcode data.- Throws:
IOException
- if an I/O error occurs.
-
printQR
Prints QR code.- Parameters:
size
- barcode symbol size, value between 1 and 40.eccLevel
- error control Level, value between 1 and 4.- L (7%)
- M (15%)
- Q (25%)
- H (30%)
barcode
- barcode data.- Throws:
IOException
- if an I/O error occurs.
-
printPDF417
public void printPDF417(boolean truncate, boolean binaryEncode, int eccLevel, int size, byte[] barcode) throws IOException Prints PDF417.- Parameters:
truncate
- truncate barcode.binaryEncode
- true to use binary encode mode, otherwise use auto proper encode.eccLevel
- error correction control, a value from 0 to 7.size
- barcode size regarding printer combination table, a value from 0 to 15.barcode
- binary barcode data.- Throws:
IOException
- if an I/O error occurs.
-
printPDF417
public void printPDF417(boolean truncate, boolean binaryEncode, int eccLevel, int size, String barcode) throws IOException Prints PDF417.- Parameters:
truncate
- truncate barcode.binaryEncode
- true to use binary encode mode, otherwise use auto proper encode.eccLevel
- error correction control, a value from 0 to 7.size
- barcode size regarding printer combination table, a value from 0 to 15.barcode
- barcode data.- Throws:
IOException
- if an I/O error occurs.
-
printBitmapRaster
public void printBitmapRaster(int[] argb, int width, int height, HorizontalAlignment align, boolean dither, boolean crop) throws IOException - Throws:
IOException
-
printBitmap
public void printBitmap(int[] argb, int width, int height, HorizontalAlignment align, boolean dither) throws IOException - Throws:
IOException
-
printBitmap
public void printBitmap(android.graphics.Bitmap bitmap, HorizontalAlignment align, boolean dither) throws IOException Prints bitmap image.- Parameters:
bitmap
- the bitmap.align
- the alignment of printed image.dither
- the flag indicates whether to perform error diffusion using Floyd-Stainberg algorithm.- Throws:
IOException
- if an I/O error occurs.
-
printBitmap
Prints bitmap image.- Parameters:
bitmap
- the bitmap.- Throws:
IOException
- if an I/O error occurs.
-
lineFeed
Executes the linefeed with specified number of lines.In standard mode prints data in the print buffer and makes paper feed forward by specified number of lines.
In page mode move along y-axis in the forward direction by specified number of lines.In standard mode prints data in the print buffer and makes paper feed.
- Parameters:
lines
- number of lines to feed.- Throws:
IOException
- if an I/O error occurs.
-
paperFeed
Feeds forward/back the paper based on specified dot pitch.- Parameters:
lines
- specifies the paper feed with dot-pitch value from -255 to 255. If parameter is negative value, the command perform printing and back feed, otherwise perform printing and feed forward.- Throws:
IOException
- if an I/O error occurs.
-
printStringAndroidFont
public void printStringAndroidFont(String text, int x, int y, android.graphics.Paint paint) throws IOException Converts the strings on Android font to Raster image and prints it.- Parameters:
text
- the text.x
- horizontal print position.y
- vertical print position.paint
- The paint used for the text (e.g. color, size, style).- Throws:
IOException
- if an I/O error occurs.
-
startPageMode
Starts page mode.- Throws:
IOException
- if an I/O error occurs.
-
setPageAttribute
public void setPageAttribute(int x, int y, int width, int height, PageDirection direction) throws IOException Sets attribute parameters for page mode.- Parameters:
x
- X-axis origin.y
- Y-axis origin.width
- X-axis length.height
- Y-axis length.direction
- printing direction and initial position.- Throws:
IOException
- if an I/O error occurs.
-
setPageAttribute
Sets attribute parameters for page mode.- Parameters:
x
- X-axis origin.y
- Y-axis origin.width
- X-axis length.height
- Y-axis length.- Throws:
IOException
- if an I/O error occurs.
-
setPageAttribute
Sets attribute parameters for page mode.- Parameters:
direction
- printing direction and initial position.- Throws:
IOException
- if an I/O error occurs.
-
endPageMode
Ends page mode after page memory batch printing.- Throws:
IOException
- if an I/O error occurs.
-
getStatus
Check printer status.- Parameters:
timeoutMillis
- the timeout in milliseconds.- Returns:
- the printer status bytes or 'null' if timeout occurs.
- Throws:
IOException
- if an I/O error occurs.
-
getStatus
Check printer status.- Returns:
- the printer status bytes or 'null' if timeout occurs.
- Throws:
IOException
- if an I/O error occurs.
-
outputRawData
Sends the binary data on byte array to the printer port.- Parameters:
output
- the data.offset
- the start offset in the data.length
- the number of bytes to write.- Throws:
IOException
- if an I/O error occurs.
-
outputRawData
Sends the binary data on byte array to the printer port.- Parameters:
output
- the data.- Throws:
IOException
- if an I/O error occurs.
-
outputRawData
Sends the byte to the printer port.- Parameters:
b
- the byte.- Throws:
IOException
- if an I/O error occurs.
-
inputRawData
Gets the binary data read on byte array from the printer port.- Parameters:
input
- the buffer into which the data is read.offset
- the start offset in array b at which the data is written.length
- the maximum number of bytes to read.timeoutMillis
- the timeout.- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException
- if an I/O error occurs.
-
inputRawData
Gets the binary data read on byte array from the printer port.- Parameters:
input
- the buffer into which the data is read.timeoutMillis
- the timeout.- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException
- if an I/O error occurs.
-
inputRawData
Gets the next byte from the printer port.- Parameters:
timeoutMillis
- the timeout.- Returns:
- the next byte of data, or -1 if there is no data.
- Throws:
IOException
- if an I/O error occurs.
-