com.sap.ip.me.api.pios.printer
Interface PrinterBarcode


public interface PrinterBarcode

This interface defines a barcode to be printed and provides a method to obtain the barcode metrics to position it when printed. The user of this interface has to create an instance of printer barcode through the PrinterConnection class specifying the symbology and other barcode options. Supported symbologies and options vary according to printer make and model. Special consideration must be taken when using some symbologies. The check digit for some symbologies is optional. To calculate and print the check digit on a barcode, set the desired check digit option in the symbology object. Query the printer capabilities to determine if a particular symbology functionality is supported. The size and density of the barcode can be controlled using the API. The size of a barcode can be scale down or up using provided methods and constants.

for more information about barcode symbologies and their uses visit the following sites:

Example: Print a Code39 barcode with check digit mode 43
 
	Connector connector = Connector.getInstance();

	DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
	PrinterParameters parameters = new PrinterParameters(printers[0]);
	parameters.setPrinterMode(PrinterParameters.GRAPHIC_MODE);
	
	GraphicPrinter printer = (GraphicPrinter)connector.open(parameters);
	
	Code39 code39 = new Code39(Code39.FULLASCII | Code39.CHECK_DIGIT_MOD43);
	PrinterBarcode barcode = printer.createBarcode(code39, PrinterBarcode.HUMAN_READABLE_BELOW);
	barcode.setHeight(200);
 	
	printer.drawBarcode(barcode, 100, 100, "ABC123".getBytes("ASCII"), 
			GraphicPrinter.ROTATE_90_DEGREES);
		
	printer.doPrint(1);
	printer.close(); 
 
 
UPC/EAN Symbologies

UPC/EAN barcodes do not support human readable above. When specifying 2 digits or 5 digits extensions for UPC/EAN symbology, the digits for the extension should be appended at the end of the data. Depending on the symbology options, the length of the data should be fixed. The digits after the length of the data will be considered the extension.

Example: Draw a small UPC barcode with a five digit add-on
 
	Connector connector = Connector.getInstance();

	DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
	PrinterParameters parameters = new PrinterParameters(printers[0]);
	parameters.setPrinterMode(PrinterParameters.GRAPHIC_MODE);
	
	GraphicPrinter printer = (GraphicPrinter)connector.open(parameters);
	
	UPC_A upcA = new UPC_A(UPC_A.FIVE_DIGIT_ADDON);
	PrinterBarcode barcode = printer.createBarcode(upcA, PrinterBarcode.HUMAN_READABLE_BELOW);
	barcode.setHeight(200);

	// 01234567891	- UPC A Barcode data
	// 00321		- five digit addon
	printer.drawBarcode(barcode, 100, 100, "0123456789100321".getBytes("ASCII"), 
		GraphicPrinter.NO_ROTATION);
					
	printer.doPrint(1);
	printer.close();
 
 
PDF417

This is a 2D symbology suitable for applications requiring a lot of encoded data. This symbology requires additional attributes to be able to print the barcode. Number of columns and number of rows must be provided.

Example: Draw a PDF417 barcode
 
	Connector connector = Connector.getInstance();

	DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
	PrinterParameters parameters = new PrinterParameters(printers[0]);
	parameters.setPrinterMode(PrinterParameters.GRAPHIC_MODE);
	
	GraphicPrinter printer = (GraphicPrinter)connector.open(parameters);

	PDF417 pdf = new PDF417(PDF417.SECURITY_LEVEL_AUTOMATIC);
				
	//Setting additional required symbology attributes
	pdf.setColumns(5);
	pdf.setRows(5);
	
	PrinterBarcode pdfBarcode = printer.createBarcode(pdf, PrinterBarcode.NONE);
	pdfBarcode.setHeight(200);
	
	printer.drawBarcode(pdfBarcode, 100, 100, "666840327895555THIS PACKAGE CONTAINS NOTHING".getBytes("ASCII"), 
		GraphicPrinter.NO_ROTATION);
						
	printer.doPrint(1);
	printer.close();
 
 
Example: Draw a small code 128 barcode starting with codeset A
 
	Connector connector = Connector.getInstance();

	DriverInfo[] printers = connector.listDrivers(ConnectionType.PRINTER);
	PrinterParameters parameters = new PrinterParameters(printers[0]);
	parameters.setPrinterMode(PrinterParameters.GRAPHIC_MODE);
	
	GraphicPrinter printer = (GraphicPrinter)connector.open(parameters);

	Code128 code128 = new Code128(Code128.A);
	
	PrinterBarcode barcode = printer.createBarcode(code128, PrinterBarcode.NONE);
	barcode.setHeight(200);
	
	printer.drawBarcode(barcode, 100, 100, "/** Code128 Test /**".getBytes("ASCII"), 
		GraphicPrinter.NO_ROTATION);

	printer.doPrint(1);
	printer.close();
 
 

Since:
MI 2.5
Author:
Abaco
See Also:
PrinterConnection, Symbology

Field Summary
static int DENSITY_DEFAULT
          Constant to indicate a default density.
static int DENSITY_HIGH
          Constant to indicate a high density.
static int DENSITY_LOW
          Constant to indicate a low density.
static long HUMAN_READABLE_ABOVE
          Constant to indicate a human readable line above the barcode.
static long HUMAN_READABLE_BELOW
          Constant to indicate a human readable line below the barcode.
static int NO_SCALE
          Default barcode size.
static long NONE
          Constant to indicate no options.
static int SCALE_DOUBLE
          Double the size of a barcode.
static int SCALE_HALF
          Decrease the barcode size to half the default size
static int SCALE_TRIPLE
          Triple the default size of a barcode for better reading at long range.
 
Method Summary
 int getDensity()
          Returns the barcode density.
 float getHeight()
          Returns the height of the barcode specified in setHeight().
 Metrics getMetrics(byte[] data)
          Returns the barcode metrics for the encoded data in the barcode.
 long getOptions()
          Returns the barcode drawing options.
 int getScaleFactor()
          Returns the barcode scale factor.
 Symbology getSymbology()
          Returns the barcode symbology instance for this barcode object.
 void setDensity(int density)
          Sets the density attribute for a barcode.
 void setHeight(float height)
          Sets the barcode height in points.
 void setOptions(long options)
          Sets the barcode options.
 void setScaleFactor(int factor)
          Set barcode scale factor.
 

Field Detail

NONE

public static final long NONE
Constant to indicate no options.

See Also:
Constant Field Values

HUMAN_READABLE_BELOW

public static final long HUMAN_READABLE_BELOW
Constant to indicate a human readable line below the barcode.

See Also:
Constant Field Values

HUMAN_READABLE_ABOVE

public static final long HUMAN_READABLE_ABOVE
Constant to indicate a human readable line above the barcode.

See Also:
Constant Field Values

DENSITY_LOW

public static final int DENSITY_LOW
Constant to indicate a low density. Not all printer support changing the barcode density. If density is different than default and printer does not supports it, default will be used.

See Also:
Constant Field Values

DENSITY_DEFAULT

public static final int DENSITY_DEFAULT
Constant to indicate a default density.

See Also:
Constant Field Values

DENSITY_HIGH

public static final int DENSITY_HIGH
Constant to indicate a high density. Not all printer support changing the barcode density. If density is different than default and printer does not supports it, default will be used.

See Also:
Constant Field Values

SCALE_HALF

public static final int SCALE_HALF
Decrease the barcode size to half the default size

See Also:
Constant Field Values

NO_SCALE

public static final int NO_SCALE
Default barcode size.

See Also:
Constant Field Values

SCALE_DOUBLE

public static final int SCALE_DOUBLE
Double the size of a barcode.

See Also:
Constant Field Values

SCALE_TRIPLE

public static final int SCALE_TRIPLE
Triple the default size of a barcode for better reading at long range.

See Also:
Constant Field Values
Method Detail

getSymbology

public Symbology getSymbology()
Returns the barcode symbology instance for this barcode object.

Returns:
The barcode symbology.

getMetrics

public Metrics getMetrics(byte[] data)
                   throws PrinterException
Returns the barcode metrics for the encoded data in the barcode. Human readable text will be considered when calculating barcode height. Some printers may not provide accurate size information.

Parameters:
data - the barcode data
Returns:
A Metrics object.
Throws:
PrinterException - thrown if unable to calculate barcode metrics

setHeight

public void setHeight(float height)
Sets the barcode height in points. Required when printing the barcode.

Parameters:
height - the barcode height in points

getHeight

public float getHeight()
Returns the height of the barcode specified in setHeight(). Use getMetrics(byte[]) to get the printed barcode height. This method does not applies to 2D symbologies.

Returns:
The height of the barcode in points.

setDensity

public void setDensity(int density)
                throws PrinterException
Sets the density attribute for a barcode.

Parameters:
density - the barcode density
Throws:
PrinterException - thrown if invalid parameter value is used

getDensity

public int getDensity()
Returns the barcode density.

Returns:
The barcode density.

setScaleFactor

public void setScaleFactor(int factor)
                    throws PrinterException
Set barcode scale factor. Use to decrease or increase the size of a barcode proportionally.

Parameters:
factor - one of the available barcode scale factors
Throws:
PrinterException - thrown if invalid parameter value is used

getScaleFactor

public int getScaleFactor()
Returns the barcode scale factor.


setOptions

public void setOptions(long options)
                throws PrinterException
Sets the barcode options.

Parameters:
options - the barcode options mask
Throws:
PrinterException - thrown if invalid option value is used

getOptions

public long getOptions()
Returns the barcode drawing options.

Returns:
The barcode options.


Copyright © 2005 SAP AG. All Rights Reserved.