com.sap.ip.me.api.pios.printer
Class PrinterConnection

java.lang.Object
  extended bycom.sap.ip.me.api.pios.connection.Connection
      extended bycom.sap.ip.me.api.pios.printer.PrinterConnection
Direct Known Subclasses:
GraphicPrinter, LinePrinter

public abstract class PrinterConnection
extends Connection

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.

Since:
MI 2.5
Author:
Abaco
See Also:
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

STATUS_IDLE

public static final int STATUS_IDLE
Constant to indicate that the printer is idle.

See Also:
Constant Field Values

STATUS_OUT_OF_PAPER

public static final int STATUS_OUT_OF_PAPER
Constant to indicate that the printer is out of paper.

See Also:
Constant Field Values

STATUS_DATA_ERROR

public static final int STATUS_DATA_ERROR
Constant to indicate that a data error occurred.

See Also:
Constant Field Values

STATUS_OUT_OF_MEMORY_ERROR

public static final int STATUS_OUT_OF_MEMORY_ERROR
Constant to indicate out of memory error occurred.

See Also:
Constant Field Values

STATUS_FONT_NOT_AVAILABLE_ERROR

public static final int STATUS_FONT_NOT_AVAILABLE_ERROR
Constant to indicate font not available.

See Also:
Constant Field Values

STATUS_INVALID_COORDINATE_ERROR

public static final int STATUS_INVALID_COORDINATE_ERROR
Constant to indicate invalid coordinate parameters.

See Also:
Constant Field Values

STATUS_UNKNOWN_ERROR

public static final int STATUS_UNKNOWN_ERROR
Constant to indicate that status of the printer is unknown.

See Also:
Constant Field Values

STATUS_BUSY

public static final int STATUS_BUSY
Constant to indicate printer busy.

See Also:
Constant Field Values
Constructor Detail

PrinterConnection

protected PrinterConnection()
                     throws PIOSException
Constructs a new printer connection.

Throws:
PIOSException - thrown if an error is detected while creating/ opening the printer connection.
Method Detail

getStatus

public abstract int getStatus()
                       throws PrinterException
Returns printer status. Example: Determine if printer is idle
 
 
	Connector connector = Connector.getInstance();

	DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
     	
	if (printers[0].getStatus() == PrinterConnection.STATUS_IDLE) {
 		//Add some code here 
	} 

 
 

Returns:
The current printer status.
Throws:
PrinterException - thrown if unable to get status from printer

getPrinterDPI

public abstract int getPrinterDPI()
                           throws PrinterException
Returns the printer's dots per inch (DPI) resolution

Returns:
The printers dots per inch (DPI).
Throws:
PrinterException - thrown if unable to get printer's DPI resolution

getPrintHeadWidth

public abstract float getPrintHeadWidth()
                                 throws PrinterException
Returns the printer's print head width in points

Returns:
The printers print head width.
Throws:
PrinterException - thrown if unable to get print head width from printer

clearError

public abstract void clearError()
                         throws PrinterException,
                                UnsupportedException
Clear printer error.

Throws:
PrinterException - thrown if unable to clear printer's error.
UnsupportedException - thrown if clearing a printer error is not supported by the printer

sendRawBytes

public abstract void sendRawBytes(byte[] rawBytes)
                           throws PrinterException,
                                  UnsupportedException
Use this method to send bytes to printer. This method should only be used when API doesn't support a specific printer capability. Remember that if you use this method in your application and then change printers, the application might not work because it is highly probable that the command for one printer will not work for another. It is an advanced mode.

Parameters:
rawBytes - the bytes containing the printer command
Throws:
PrinterException - thrown if there is an error sending bytes to the printer.
UnsupportedException - thrown if sending of raw bytes is not supported by the printer

listFonts

public abstract PrinterFont[] listFonts(float size,
                                        int fontType,
                                        long options)
                                 throws PrinterException
Returns the list of configured fonts sorted by name, filtered by size, font type, and printer font options. The filter parameter is ignored when a 0 value is specified. A list of all configured fonts is returned when 0, 0, and PrinterFont.OPTION_ANY values are specified for parameters size, fontType, and options, respectively. In the case no matching font is found an empty array is returned.

Parameters:
size - the requested font size in points
fontType - the requested font type
options - the requested font options
Returns:
The list of available fonts that match criteria.
Throws:
PrinterException - thrown if unable to get printer's fonts information.

getFont

public abstract PrinterFont getFont(java.lang.String name)
                             throws PrinterException
Returns a PrinterFont object by name. The name of a font is a logical name mapped to physical printer's font name.

Parameters:
name - the font name
Returns:
The PrinterFont object.
Throws:
PrinterException - thrown if font was not configured
See Also:
How to configure fonts

getFontConfigurationManager

public abstract FontConfigurationManager getFontConfigurationManager()
                                                              throws ConfigurationException
Returns the FontConfigurationManager object for this printer connection.

Returns:
A FontConfigurationManager object.
Throws:
ConfigurationException - thrown when unable to return the font configuration manager for this connection.

createBarcode

public abstract PrinterBarcode createBarcode(Symbology symbology,
                                             long options)
                                      throws UnsupportedException,
                                             InvalidSymbologyException,
                                             PrinterException
Creates a barcode object. UPC/EAN linear symbologies only allow human readable below options. 2D symbologies do not allow any human readable options.

Parameters:
symbology - the symbology object
options - the barcode options such as HUMAN_READABLE_ABOVE, HUMAN_READABLE_BELOW
Returns:
The Printer barcode object.
Throws:
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 barcode
See Also:
Symbology, PrinterBarcode

createImage

public abstract PrinterImage createImage(java.lang.String name,
                                         int imageType,
                                         byte[] image)
                                  throws UnsupportedException,
                                         PrinterException
Creates a printer image from a byte array. Validates if image type is supported by printer. The image name length must not be greater than 16 characters. An image name may contain only alphanumeric characters. Image names are not case sensitive.

Parameters:
name - the image name
imageType - the image type
image - the image byte array
Returns:
A PrinterImage object.
Throws:
UnsupportedException - thrown if the image type is not supported by the printer.
PrinterException - thrown if there is an error creating the printer image.

doPrint

public abstract void doPrint(int copies)
                      throws PrinterException
Sends all buffered printing commands to the printer. Afterward, the command buffer is cleared.

Parameters:
copies - the number of copies to print.
Throws:
PrinterException - thrown if there is an error sending the buffered printing command to the printer.

advance

public abstract void advance(float points)
                      throws UnsupportedException,
                             PrinterException
Advances the paper forward in points specified by a positive number or backwards in points specified by a negative number. Some printers may not support this functionality. this command is sent immediately to the printer and cannot be buffered.

Parameters:
points - the distance to advance forward or backward in points
Throws:
UnsupportedException - thrown if advance capability is not supported by the printer
PrinterException - thrown if there was an error advancing

dispose

public abstract void dispose()
                      throws PrinterException
Cancels all buffered commands stored by the driver.

Throws:
PrinterException - thrown if there was an error canceling buffered commands

loadImage

public abstract void loadImage(PrinterImage image)
                        throws UnsupportedException,
                               PrinterException
Loads image to printer's memory. The command is sent immediately to the printer. The image name length must not be greater than 16 characters. An image name may contain only alphanumeric characters. Image names are not case sensitive.

Parameters:
image - the printer image object
Throws:
UnsupportedException - thrown if upload images is not supported by the printer
PrinterException - thrown if there was an error sending image to printer

deleteImage

public abstract void deleteImage(java.lang.String name)
                          throws UnsupportedException,
                                 PrinterException
Deletes preloaded image from printer's memory. The command will be sent immediately to the printer.

Parameters:
name - the image name
Throws:
UnsupportedException - thrown if deleting images is not supported by the printer
PrinterException - thrown if there was an error deleting the image


Copyright © 2005 SAP AG. All Rights Reserved.