|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sap.ip.me.api.pios.connection.Connection
com.sap.ip.me.api.pios.printer.PrinterConnection
Defines a base class for a printer connection. This class includes common methods to all types of printer. Some printers may support more than one printing mode, for example, line mode and graphic mode. A printer connection includes methods to list available fonts, request a font by name, create a barcode object, and to create image objects. It can also query the status of the printer and reset it in case of error.
Example: Get a scalable bold font object
Connector connector = Connector.getInstance();
DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
PrinterParameters parameters = new PrinterParameters(printers[0]);
parameters.setPrinterMode(PrinterParameters.LINE_MODE);
LinePrinter printer = (LinePrinter)connector.open(parameters);
PrinterFont[] fonts = printer.listFonts(0, PrinterFont.FONTTYPE_SCALABLE, PrinterFont.OPTION_BOLD);
ScalableFont scalable;
if (fonts.length > 0) {
scalable = (ScalableFont)fonts[0];
scalable.setFontSize(16);
Metrics fd = scalable.getMetrics("MY SCALABLE FONT");
}
//Add some code here
printer.doPrint(1);
printer.close();
To determine if a required printer functionality is provided by a driver use a DriverInfo instance provided by the connector. Example: Determine is a printer supports text rotation
Connector connector = Connector.getInstance();
DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
if (printers[0].isAttributeSupported(PrinterConnection.Attributes.TEXT_ROTATION)) {
//Add some code here
}
Many printers support image printing. The image can be stored at the printer's memory and later accessed by name. To store the image in printer's memory use the loadImage method. Recall the image by name when using printer commands.
PrinterParameters
,
Connection
,
PrinterBarcode
,
PrinterFont
Nested Class Summary | |
static interface |
PrinterConnection.Attributes
Contains all possible attribute names for the printer. |
Field Summary | |
static int |
STATUS_BUSY
Constant to indicate printer busy. |
static int |
STATUS_DATA_ERROR
Constant to indicate that a data error occurred. |
static int |
STATUS_FONT_NOT_AVAILABLE_ERROR
Constant to indicate font not available. |
static int |
STATUS_IDLE
Constant to indicate that the printer is idle. |
static int |
STATUS_INVALID_COORDINATE_ERROR
Constant to indicate invalid coordinate parameters. |
static int |
STATUS_OUT_OF_MEMORY_ERROR
Constant to indicate out of memory error occurred. |
static int |
STATUS_OUT_OF_PAPER
Constant to indicate that the printer is out of paper. |
static int |
STATUS_UNKNOWN_ERROR
Constant to indicate that status of the printer is unknown. |
Fields inherited from class com.sap.ip.me.api.pios.connection.Connection |
attributesFileName, cfgFile, opened, parameters |
Constructor Summary | |
protected |
PrinterConnection()
Constructs a new printer connection. |
Method Summary | |
abstract void |
advance(float points)
Advances the paper forward in points specified by a positive number or backwards in points specified by a negative number. |
abstract void |
clearError()
Clear printer error. |
abstract PrinterBarcode |
createBarcode(Symbology symbology,
long options)
Creates a barcode object. |
abstract PrinterImage |
createImage(java.lang.String name,
int imageType,
byte[] image)
Creates a printer image from a byte array. |
abstract void |
deleteImage(java.lang.String name)
Deletes preloaded image from printer's memory. |
abstract void |
dispose()
Cancels all buffered commands stored by the driver. |
abstract void |
doPrint(int copies)
Sends all buffered printing commands to the printer. |
abstract PrinterFont |
getFont(java.lang.String name)
Returns a PrinterFont object by name. |
abstract FontConfigurationManager |
getFontConfigurationManager()
Returns the FontConfigurationManager object for this printer connection. |
abstract int |
getPrinterDPI()
Returns the printer's dots per inch (DPI) resolution |
abstract float |
getPrintHeadWidth()
Returns the printer's print head width in points |
abstract int |
getStatus()
Returns printer status. |
abstract PrinterFont[] |
listFonts(float size,
int fontType,
long options)
Returns the list of configured fonts sorted by name, filtered by size, font type, and printer font options. |
abstract void |
loadImage(PrinterImage image)
Loads image to printer's memory. |
abstract void |
sendRawBytes(byte[] rawBytes)
Use this method to send bytes to printer. |
Methods inherited from class com.sap.ip.me.api.pios.connection.Connection |
close, getParameters, isOpen, open |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int STATUS_IDLE
public static final int STATUS_OUT_OF_PAPER
public static final int STATUS_DATA_ERROR
public static final int STATUS_OUT_OF_MEMORY_ERROR
public static final int STATUS_FONT_NOT_AVAILABLE_ERROR
public static final int STATUS_INVALID_COORDINATE_ERROR
public static final int STATUS_UNKNOWN_ERROR
public static final int STATUS_BUSY
Constructor Detail |
protected PrinterConnection() throws PIOSException
PIOSException
- thrown if an error is detected while creating/
opening the printer connection.Method Detail |
public abstract int getStatus() throws PrinterException
Connector connector = Connector.getInstance();
DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
if (printers[0].getStatus() == PrinterConnection.STATUS_IDLE) {
//Add some code here
}
PrinterException
- thrown if unable to get status from printerpublic abstract int getPrinterDPI() throws PrinterException
PrinterException
- thrown if unable to get printer's DPI resolutionpublic abstract float getPrintHeadWidth() throws PrinterException
PrinterException
- thrown if unable to get print head width from printerpublic abstract void clearError() throws PrinterException, UnsupportedException
PrinterException
- thrown if unable to clear printer's error.
UnsupportedException
- thrown if clearing a printer error is not
supported by the printerpublic abstract void sendRawBytes(byte[] rawBytes) throws PrinterException, UnsupportedException
rawBytes
- the bytes containing the printer command
PrinterException
- thrown if there is an error sending bytes to the printer.
UnsupportedException
- thrown if sending of raw bytes is not
supported by the printerpublic abstract PrinterFont[] listFonts(float size, int fontType, long options) throws PrinterException
size
- the requested font size in pointsfontType
- the requested font typeoptions
- the requested font options
PrinterException
- thrown if unable to get printer's fonts information.public abstract PrinterFont getFont(java.lang.String name) throws PrinterException
name
- the font name
PrinterException
- thrown if font was not configuredHow to configure fonts
public abstract FontConfigurationManager getFontConfigurationManager() throws ConfigurationException
ConfigurationException
- thrown when unable to return the
font configuration manager for this connection.public abstract PrinterBarcode createBarcode(Symbology symbology, long options) throws UnsupportedException, InvalidSymbologyException, PrinterException
symbology
- the symbology objectoptions
- the barcode options such as HUMAN_READABLE_ABOVE, HUMAN_READABLE_BELOW
UnsupportedException
- thrown if barcode creation or symbology is not supported by printer.
InvalidSymbologyException
- thrown when symbology options are invalid
PrinterException
- thrown when unable to create barcodeSymbology
,
PrinterBarcode
public abstract PrinterImage createImage(java.lang.String name, int imageType, byte[] image) throws UnsupportedException, PrinterException
name
- the image nameimageType
- the image typeimage
- the image byte array
UnsupportedException
- thrown if the image type is not supported by the printer.
PrinterException
- thrown if there is an error creating the printer image.public abstract void doPrint(int copies) throws PrinterException
copies
- the number of copies to print.
PrinterException
- thrown if there is an error sending
the buffered printing command to the printer.public abstract void advance(float points) throws UnsupportedException, PrinterException
points
- the distance to advance forward or backward in points
UnsupportedException
- thrown if advance capability is not
supported by the printer
PrinterException
- thrown if there was an error advancingpublic abstract void dispose() throws PrinterException
PrinterException
- thrown if there was an error canceling buffered commandspublic abstract void loadImage(PrinterImage image) throws UnsupportedException, PrinterException
image
- the printer image object
UnsupportedException
- thrown if upload images is not supported
by the printer
PrinterException
- thrown if there was an error sending image to printerpublic abstract void deleteImage(java.lang.String name) throws UnsupportedException, PrinterException
name
- the image name
UnsupportedException
- thrown if deleting images is not supported
by the printer
PrinterException
- thrown if there was an error deleting the image
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |