Class PrinterDevice

java.lang.Object
jp.co.sanei_elec.printerlibrary.api.PrinterDevice

public class PrinterDevice extends Object
  • 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

      public void setPrinterListener(PrinterListener l)
      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

      public void connectPrinter(AbstractConnector connector) throws IOException
      Connect to printer.
      Parameters:
      connector - the connector instance.
      Throws:
      IOException - if an I/O error occurs.
    • connectPrinter

      public void connectPrinter(android.bluetooth.BluetoothDevice device) throws IOException
      Connects to Bluetooth printer.
      Parameters:
      device - Bluetooth device.
      Throws:
      IOException - if an I/O error occurs.
    • connectPrinter

      public void connectPrinter(android.hardware.usb.UsbDevice device) throws IOException
      Connects to USB printer.
      Parameters:
      device - USB device.
      Throws:
      IOException - if an I/O error occurs.
    • connectPrinter

      public void connectPrinter(String host, int port) throws IOException
      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

      public AbstractConnector 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 return false.
    • initPrinter

      public void initPrinter() throws IOException
      Initialize printed with default settings.
      Throws:
      IOException - if an I/O error occurs.
    • printString

      public void printString(String data) throws IOException
      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

      public void printString(String data, String charsetName) throws IOException
      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

      public void setFontType(boolean compact) throws IOException
      Set character font type.
      Parameters:
      compact - specify small font size.
      Throws:
      IOException - if an I/O error occurs.
    • setFontStyle

      public void setFontStyle(boolean bold, boolean italic, boolean underline) throws IOException
      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

      public void setFontMagnification(int horizontalRation, int verticalRatio) throws IOException
      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

      public void setFontColor(boolean reverse) throws IOException
      Set font color.
      Parameters:
      reverse - specify black and white reverse character.
      Throws:
      IOException - if an I/O error occurs.
    • setFontSmoothing

      public void setFontSmoothing(boolean on) throws IOException
      Set or cancel font smoothing.
      Parameters:
      on - specify font smoothing.
      Throws:
      IOException - if an I/O error occurs.
    • setAlignment

      public void setAlignment(HorizontalAlignment alignment) throws IOException
      Align the printing data at specified position.
      Parameters:
      alignment - the printing alignment.
      Throws:
      IOException - if an I/O error occurs.
    • setCodePage

      public void setCodePage(CodePage codePage) throws IOException
      Sets a code page character.
      Parameters:
      codePage - character code page.
      Throws:
      IOException - if an I/O error occurs.
    • setInternationalChar

      public void setInternationalChar(InternationalCharset internationalCharset) throws IOException
      Sets an international character.
      Parameters:
      internationalCharset - international charset of country.
      Throws:
      IOException - if an I/O error occurs.
    • setBarcodeModification

      public void setBarcodeModification(HRI hri, int width, int height) throws IOException
      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

      public void printBarcode(BarcodeSystem barcodeSystem, byte[] barcode) throws IOException
      Prints 1D barcode.
      Parameters:
      barcodeSystem - barcode system.
      barcode - barcode data.
      Throws:
      IOException - if an I/O error occurs.
    • printBarcode

      public void printBarcode(BarcodeSystem barcodeSystem, String barcode) throws IOException
      Prints 1D barcode.
      Parameters:
      barcodeSystem - barcode system.
      barcode - barcode data.
      Throws:
      IOException - if an I/O error occurs.
    • printQR

      public void printQR(int size, int eccLevel, byte[] barcode) throws IOException
      Prints QR code.
      Parameters:
      size - barcode symbol size, value between 1 and 40.
      eccLevel - error control Level, value between 1 and 4.
      1. L (7%)
      2. M (15%)
      3. Q (25%)
      4. H (30%)
      barcode - barcode data.
      Throws:
      IOException - if an I/O error occurs.
    • printQR

      public void printQR(int size, int eccLevel, String barcode) throws IOException
      Prints QR code.
      Parameters:
      size - barcode symbol size, value between 1 and 40.
      eccLevel - error control Level, value between 1 and 4.
      1. L (7%)
      2. M (15%)
      3. Q (25%)
      4. 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

      public void printBitmap(android.graphics.Bitmap bitmap) throws IOException
      Prints bitmap image.
      Parameters:
      bitmap - the bitmap.
      Throws:
      IOException - if an I/O error occurs.
    • lineFeed

      public void lineFeed(int lines) throws IOException
      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

      public void paperFeed(int lines) throws IOException
      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

      public void startPageMode() throws IOException
      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

      public void setPageAttribute(int x, int y, int width, int height) 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.
      Throws:
      IOException - if an I/O error occurs.
    • setPageAttribute

      public void setPageAttribute(PageDirection direction) throws IOException
      Sets attribute parameters for page mode.
      Parameters:
      direction - printing direction and initial position.
      Throws:
      IOException - if an I/O error occurs.
    • endPageMode

      public void endPageMode() throws IOException
      Ends page mode after page memory batch printing.
      Throws:
      IOException - if an I/O error occurs.
    • getStatus

      public PrinterStatus getStatus(int timeoutMillis) throws IOException
      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

      public PrinterStatus getStatus() throws IOException
      Check printer status.
      Returns:
      the printer status bytes or 'null' if timeout occurs.
      Throws:
      IOException - if an I/O error occurs.
    • outputRawData

      public void outputRawData(byte[] output, int offset, int length) throws IOException
      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

      public void outputRawData(byte[] output) throws IOException
      Sends the binary data on byte array to the printer port.
      Parameters:
      output - the data.
      Throws:
      IOException - if an I/O error occurs.
    • outputRawData

      public void outputRawData(int b) throws IOException
      Sends the byte to the printer port.
      Parameters:
      b - the byte.
      Throws:
      IOException - if an I/O error occurs.
    • inputRawData

      public int inputRawData(byte[] input, int offset, int length, int timeoutMillis) throws IOException
      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

      public int inputRawData(byte[] input, int timeoutMillis) throws IOException
      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

      public int inputRawData(int timeoutMillis) throws IOException
      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.