|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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();
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 |
public static final long NONE
public static final long HUMAN_READABLE_BELOW
public static final long HUMAN_READABLE_ABOVE
public static final int DENSITY_LOW
public static final int DENSITY_DEFAULT
public static final int DENSITY_HIGH
public static final int SCALE_HALF
public static final int NO_SCALE
public static final int SCALE_DOUBLE
public static final int SCALE_TRIPLE
Method Detail |
public Symbology getSymbology()
public Metrics getMetrics(byte[] data) throws PrinterException
data
- the barcode data
PrinterException
- thrown if unable to calculate barcode metricspublic void setHeight(float height)
height
- the barcode height in pointspublic float getHeight()
public void setDensity(int density) throws PrinterException
density
- the barcode density
PrinterException
- thrown if invalid parameter value is usedpublic int getDensity()
public void setScaleFactor(int factor) throws PrinterException
factor
- one of the available barcode scale factors
PrinterException
- thrown if invalid parameter value is usedpublic int getScaleFactor()
public void setOptions(long options) throws PrinterException
options
- the barcode options mask
PrinterException
- thrown if invalid option value is usedpublic long getOptions()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |