org.faceless.pdf2
Class BarCode

java.lang.Object
  extended byorg.faceless.pdf2.AbstractBarCode
      extended byorg.faceless.pdf2.BarCode

public class BarCode
extends org.faceless.pdf2.AbstractBarCode

A class representing a Bar Code, which can be created and drawn onto a PDFPage object using the PDFPage.drawBarCode method.

One of several algorithms can be used, each with it's own features and limitations. For example, to draw a Code-128 barcode centered on a page, try something like this:

   float x = page.getWidth()/2;
   float y = page.getHeight()/2;

   BarCode code = new BarCode(BarCode.CODE128, "My Text");
   float w = code.getWidth();
   float h = code.getHeight();
   page.drawBarCode(code, x-w/2, y-h/2, x+w/2, y+h/2);
 

Since:
2.0
See Also:
PDFPage.drawBarCode, PDFCanvas.drawBarCode, MaxiCode

Field Summary
static int CODABAR
          Represents the "Codabar" barcode algorithm.
static int CODE128
           Represents the "Code 128" barcode algorithm.
static int CODE39
          Reresents a "Code 3 of 9" barcode.
static int CODE39_CHECKSUM
          Identical to the algorithm represented by CODE39, except a checkdigit is calculated automatically and added to the end of the code.
static int CODE39X
          Represents the "Extended Code 3 of 9" barcode.
static int CODE39X_CHECKSUM
          Identical to the algorithm represented by CODE39X, except a checkdigit is calculated automatically and added to the end of the code.
static int EAN13
          Represents the EAN-13 barcode.
static int INTERLEAVED25
          Represents the "Interleaved 2 of 5" barcode.
static int INTERLEAVED25_CHECKSUM
          Identical to the INTERLEAVED25 algorithm, except a checkdigit is added at the end.
static int INTERLEAVED25_DEUTSCHENPOST
          Represents the Interleaved 2/5 variation used by Deutschen Post in Germany for the Identcode and Leitcode algorithms.
static int MAXICODE
          Represents a UPS MaxiCode, a type of 2-Dimensional barcode.
static int POSTNET
          Represents the "PostNet" barcode algorithm, a numeric barcode used by the United States Postal Service to encode information for mail delivery in the US.
static int RM4SCC
          Represents the Royal Mail 4-state Customer Code barcode algorithm used by the Royal Mail in the the UK.
static int UPCA
          Represents the UPC-A barcode.
 
Constructor Summary
BarCode(int type, String code)
          Create a new BarCode object.
 
Method Summary
 float getHeight()
          Get the height of the barcode, not including the height of the text (if any) displayed below it.
 int getType()
          Return the type of barcode.
 float getWidth()
          Get the width of the total barcode in points.
 void setBarRatio(float ratio)
          Set the ratio between the thin and thick bars in a duel-width code - ie.
 void setBarWidth(float barwidth)
          Set the width of the narrowest bar used in this barcode.
 void setHeight(float height)
          Set the height of the barcode in points.
 void setShowText(boolean showtext)
          Set whether to show the value of the bar as human-readable text just below the barcode.
 void setWidth(float width)
          Set the desired width of the entire barcode.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CODE39

public static final int CODE39
Reresents a "Code 3 of 9" barcode. This algorithm can display digits, the 26 upper-case letters, the space character and the symbols '-', '+', '/', '.', '$' and '%'. This algorithm has two bar widths - thin and thick - and the ratio between the two can be set by the setBarRatio(float) method.

See Also:
Constant Field Values

CODE39_CHECKSUM

public static final int CODE39_CHECKSUM
Identical to the algorithm represented by CODE39, except a checkdigit is calculated automatically and added to the end of the code. The checksum algorithm is described on this page.

See Also:
Constant Field Values

CODE39X

public static final int CODE39X
Represents the "Extended Code 3 of 9" barcode. This barcode uses the same codes as the CODE39 algorithm, but by re-encoding can display all the characters in the U+0000 to U+007F range (ie. ASCII). The re-encoding algorithm is described on this page.

See Also:
Constant Field Values

CODE39X_CHECKSUM

public static final int CODE39X_CHECKSUM
Identical to the algorithm represented by CODE39X, except a checkdigit is calculated automatically and added to the end of the code. The checksum algorithm is described on this page.

See Also:
Constant Field Values

INTERLEAVED25

public static final int INTERLEAVED25
Represents the "Interleaved 2 of 5" barcode. This algorithm is only suitable for numbers, and requires an even number of digits (a leading "0" will be automatically added if required). This algorithm has two bar widths - thin and thick - and the ratio between the two can be set by the setBarRatio(float) method.

See Also:
Constant Field Values

INTERLEAVED25_CHECKSUM

public static final int INTERLEAVED25_CHECKSUM
Identical to the INTERLEAVED25 algorithm, except a checkdigit is added at the end. It is the value of the equation (10 - ((s[0]*3 + s[1] + s[2]*3 + s[3] and so on, multiplying every second digit by 3) % 10)) % 10

See Also:
Constant Field Values

CODE128

public static final int CODE128

Represents the "Code 128" barcode algorithm. This code can display digits, upper and lower-case letters and most punctuation characters from the U+0000 - U+007E (US-ASCII) range. A checksum is automatically included as part of the barcode.

Code 128 has three "character sets" - A, B or C - which encode different subsets of characters. At any time during the encoding process, a subset can be chosen by embedding the characters U+0091, U+0092 or U+0093 into the String being encoded, to switch to set A, B or C respectively. If no initial character set is chosen, the most appropriate one will be used. So, for example, to force a String to be encoded using set A, you could specify the string "\u0092CODEHERE".

EAN128 barcodes can also be printed by using a newline (\n) to represent the FNC1 control character.

See Also:
Constant Field Values

EAN13

public static final int EAN13
Represents the EAN-13 barcode. An EAN-13 code represents a 13 digit number - broadly speaking, the first 7 digits the country and manufacturer code, the next 5 digits the product code, and the final digit the checksum. The 12 digit UPC-A barcodes as used in the USA are just EAN-13 codes with a leading zero. By default EAN-13 bar codes are an inch wide, so the default bar width is 0.75".

See Also:
Constant Field Values

UPCA

public static final int UPCA
Represents the UPC-A barcode. Although the Uniform Code Council in the US has declared that all UPC-A readers be able to read EAN-13 codes by 2005, some clients may still prefer to use the older format 12 digit UPC-A codes. Barcodes using this code type must be 11 digits long, or 12 digits if the check digit is pre-calculated. As with EAN-13, the barcodes default to an inch wide.

See Also:
Constant Field Values

CODABAR

public static final int CODABAR
Represents the "Codabar" barcode algorithm. A Codabar code can contain the digits 0 to 9, plus the characters +, /, $, -, : and the decimal point (.). Additionally it must begin and end with a "stop letter", which may be one of A, B, C or D.

See Also:
Constant Field Values

POSTNET

public static final int POSTNET
Represents the "PostNet" barcode algorithm, a numeric barcode used by the United States Postal Service to encode information for mail delivery in the US. Unlike the other barcodes, the information is encoded in the height of the bars, rather than the bar thickness. Because of this the width and height of this barcode is fixed - the height is always 9 points, and the width is always (number of digits+1.4)*16.2 points wide.

Since:
2.0.6
See Also:
Constant Field Values

RM4SCC

public static final int RM4SCC
Represents the Royal Mail 4-state Customer Code barcode algorithm used by the Royal Mail in the the UK. This code can represent the digits 0-9 and the upper case letters A-Z. Like PostNet, the information is encoded in the height of the bars, rather than the bar thickness. Because of this the width and height of this barcode is fixed - the height is always 13 points, and the width is always (number of symbols+1.5)*13 + 12 points wide (the 12 points are the required 2mm quiet zone on either side of the code)

Since:
2.0.6
See Also:
Constant Field Values

INTERLEAVED25_DEUTSCHENPOST

public static final int INTERLEAVED25_DEUTSCHENPOST
Represents the Interleaved 2/5 variation used by Deutschen Post in Germany for the Identcode and Leitcode algorithms. This is identical to regular Interleaved 2/5 except for a difference checksum calculation

Since:
2.0.6
See Also:
Constant Field Values

MAXICODE

public static final int MAXICODE
Represents a UPS MaxiCode, a type of 2-Dimensional barcode. Note that this class of BarCode has it's own MaxiCode class - this value is only here so that the getType() method has something useful to return.

See Also:
Constant Field Values
Constructor Detail

BarCode

public BarCode(int type,
               String code)
Create a new BarCode object.

Parameters:
type - one of the barcode algorithms listed above
code - the text to encode.
Since:
2.0
Method Detail

getType

public int getType()
Return the type of barcode. This is simply the "type" value passed in to the constructor.

Since:
2.0

setShowText

public void setShowText(boolean showtext)
Set whether to show the value of the bar as human-readable text just below the barcode. The default is true.

Since:
2.0

setBarWidth

public void setBarWidth(float barwidth)
Set the width of the narrowest bar used in this barcode. The width of the barcode may be set either by calling this method, or by calling the setWidth(float) method - they are two different means to the same end. PostNet barcodes have fixed dimensions, so in that case this value will be ignored.

Parameters:
barwidth - the width of the narrowest bar used in the barcode. Minimum value is 0.54 points (= 0.0075 inches)
Since:
2.0

setWidth

public void setWidth(float width)
Set the desired width of the entire barcode. The width of the barcode may be set either by calling this method, or by calling the setBarWidth(float) method. If the specified width would result in a barcode with the minimum bar width < 0.54 points (= 0.0075 inches), an IllegalArgumentException will be thrown. PostNet barcodes have fixed dimensions, so in that case this value will be ignored.

Since:
2.0

getWidth

public float getWidth()
Get the width of the total barcode in points.

Since:
2.0

getHeight

public float getHeight()
Get the height of the barcode, not including the height of the text (if any) displayed below it. The minimum height is 18 points, except for PostNet barcodes, which are always 9 points high.

Since:
2.0

setHeight

public void setHeight(float height)
Set the height of the barcode in points. The minimum height is 18 points (except for PostNet), so any attempt to set a height shorter than that will be scaled up. PostNet barcodes are always 9 points high, so in that case this value will be ignored.

Since:
2.0

setBarRatio

public void setBarRatio(float ratio)
Set the ratio between the thin and thick bars in a duel-width code - ie. one of the Code 3 of 9 or Interleaved 2 of 5 codes. For other code types calling this method has no effect.

Since:
2.0


Copyright © 2001-2004 Big Faceless Organization