com.lowagie.text.pdf

Class Barcode128


public class Barcode128
extends Barcode

Implements the code 128 and UCC/EAN-128. Other symbologies are allowed in raw mode.

The code types allowed are:

The default parameters are:
 x = 0.8f;
 font = BaseFont.createFont("Helvetica", "winansi", false);
 size = 8;
 baseline = size;
 barHeight = size * 3;
 textAlignment = Element.ALIGN_CENTER;
 codeType = CODE128;
 
Author:
Paulo Soares (psoares@consiste.pt)

Field Summary

(package private) static byte[][]
BARS
The bars to generate the code.
(package private) static byte[]
BARS_STOP
The stop bars.
static char
CODE_A
static char
CODE_AB_TO_C
The charset code change.
static char
CODE_AC_TO_B
The charset code change.
static char
CODE_BC_TO_A
The charset code change.
static char
CODE_C
static char
DEL
static char
FNC1
static char
FNC1_INDEX
The code for UCC/EAN-128.
static char
FNC2
static char
FNC3
static char
FNC4
static char
SHIFT
static char
STARTA
static char
STARTB
static char
STARTC
static char
START_A
The start code.
static char
START_B
The start code.
static char
START_C
The start code.
private static IntHashtable
ais

Fields inherited from class com.lowagie.text.pdf.Barcode

CODABAR, CODE128, CODE128_RAW, CODE128_UCC, EAN13, EAN8, PLANET, POSTNET, SUPP2, SUPP5, UPCA, UPCE, barHeight, baseline, checksumText, code, codeType, extended, font, generateChecksum, guardBars, inkSpreading, n, size, startStopText, textAlignment, x

Constructor Summary

Barcode128()
Creates new Barcode128

Method Summary

java.awt.Image
createAwtImage(Color foreground, Color background)
Creates a java.awt.Image.
Rectangle
getBarcodeSize()
Gets the maximum area that the barcode and the text, if any, will occupy.
static byte[]
getBarsCode128Raw(String text)
Generates the bars.
static String
getHumanReadableUCCEAN(String code)
Gets the human readable text of a sequence of AI.
(package private) static String
getPackedRawDigits(String text, int textIndex, int numDigits)
Packs the digits for charset C also considering FNC1.
static String
getRawText(String text, boolean ucc)
Converts the human readable text to the characters needed to create a barcode.
(package private) static boolean
isNextDigits(String text, int textIndex, int numDigits)
Returns true if the next numDigits starting from index textIndex are numeric skipping any FNC1.
Rectangle
placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
Places the barcode in a PdfContentByte.
static String
removeFNC1(String code)
Removes the FNC1 codes in the text.
void
setCode(String code)
Sets the code to generate.

Methods inherited from class com.lowagie.text.pdf.Barcode

createAwtImage, createImageWithBarcode, createTemplateWithBarcode, getBarHeight, getBarcodeSize, getBaseline, getCode, getCodeType, getFont, getInkSpreading, getN, getSize, getTextAlignment, getX, isChecksumText, isExtended, isGenerateChecksum, isGuardBars, isStartStopText, placeBarcode, setBarHeight, setBaseline, setChecksumText, setCode, setCodeType, setExtended, setFont, setGenerateChecksum, setGuardBars, setInkSpreading, setN, setSize, setStartStopText, setTextAlignment, setX

Field Details

BARS

(package private) static byte[][] BARS
The bars to generate the code.

BARS_STOP

(package private) static byte[] BARS_STOP
The stop bars.

CODE_A

public static final char CODE_A
Field Value:
'\u00c8'

CODE_AB_TO_C

public static final char CODE_AB_TO_C
The charset code change.
Field Value:
'c'

CODE_AC_TO_B

public static final char CODE_AC_TO_B
The charset code change.
Field Value:
'd'

CODE_BC_TO_A

public static final char CODE_BC_TO_A
The charset code change.
Field Value:
'e'

CODE_C

public static final char CODE_C
Field Value:
'\u00c7'

DEL

public static final char DEL
Field Value:
'\u00c3'

FNC1

public static final char FNC1
Field Value:
'\u00ca'

FNC1_INDEX

public static final char FNC1_INDEX
The code for UCC/EAN-128.
Field Value:
'f'

FNC2

public static final char FNC2
Field Value:
'\u00c5'

FNC3

public static final char FNC3
Field Value:
'\u00c4'

FNC4

public static final char FNC4
Field Value:
'\u00c8'

SHIFT

public static final char SHIFT
Field Value:
'\u00c6'

STARTA

public static final char STARTA
Field Value:
'\u00cb'

STARTB

public static final char STARTB
Field Value:
'\u00cc'

STARTC

public static final char STARTC
Field Value:
'\u00cd'

START_A

public static final char START_A
The start code.
Field Value:
'g'

START_B

public static final char START_B
The start code.
Field Value:
'h'

START_C

public static final char START_C
The start code.
Field Value:
'i'

ais

private static final IntHashtable ais

Constructor Details

Barcode128

public Barcode128()
Creates new Barcode128

Method Details

createAwtImage

public java.awt.Image createAwtImage(Color foreground,
                                     Color background)
Creates a java.awt.Image. This image only contains the bars without any text.
Overrides:
createAwtImage in interface Barcode
Parameters:
foreground - the color of the bars
background - the color of the background
Returns:
the image

getBarcodeSize

public Rectangle getBarcodeSize()
Gets the maximum area that the barcode and the text, if any, will occupy. The lower left corner is always (0, 0).
Overrides:
getBarcodeSize in interface Barcode
Returns:
the size the barcode occupies.

getBarsCode128Raw

public static byte[] getBarsCode128Raw(String text)
Generates the bars. The input has the actual barcodes, not the human readable text.
Parameters:
text - the barcode
Returns:
the bars

getHumanReadableUCCEAN

public static String getHumanReadableUCCEAN(String code)
Gets the human readable text of a sequence of AI.
Parameters:
code - the text
Returns:
the human readable text

getPackedRawDigits

(package private) static String getPackedRawDigits(String text,
                                                   int textIndex,
                                                   int numDigits)
Packs the digits for charset C also considering FNC1. It assumes that all the parameters are valid.
Parameters:
text - the text to pack
textIndex - where to pack from
numDigits - the number of digits to pack. It is always an even number
Returns:
the packed digits, two digits per character

getRawText

public static String getRawText(String text,
                                boolean ucc)
Converts the human readable text to the characters needed to create a barcode. Some optimization is done to get the shortest code.
Parameters:
text - the text to convert
ucc - true if it is an UCC/EAN-128. In this case the character FNC1 is added
Returns:
the code ready to be fed to getBarsCode128Raw()

isNextDigits

(package private) static boolean isNextDigits(String text,
                                              int textIndex,
                                              int numDigits)
Returns true if the next numDigits starting from index textIndex are numeric skipping any FNC1.
Parameters:
text - the text to check
textIndex - where to check from
numDigits - the number of digits to check
Returns:
the check result

placeBarcode

public Rectangle placeBarcode(PdfContentByte cb,
                              Color barColor,
                              Color textColor)
Places the barcode in a PdfContentByte. The barcode is always placed at coodinates (0, 0). Use the translation matrix to move it elsewhere.

The bars and text are written in the following colors:

barColor

textColor

Result

null

null

bars and text painted with current fill color

barColor

null

bars and text painted with barColor

null

textColor

bars painted with current color
text painted with textColor

barColor

textColor

bars painted with barColor
text painted with textColor

Overrides:
placeBarcode in interface Barcode
Parameters:
cb - the PdfContentByte where the barcode will be placed
barColor - the color of the bars. It can be null
textColor - the color of the text. It can be null
Returns:
the dimensions the barcode occupies

removeFNC1

public static String removeFNC1(String code)
Removes the FNC1 codes in the text.
Parameters:
code - the text to clean
Returns:
the cleaned text

setCode

public void setCode(String code)
Sets the code to generate. If it's an UCC code and starts with '(' it will be split by the AI. This code in UCC mode is valid:

(01)00000090311314(10)ABC123(15)060916

Overrides:
setCode in interface Barcode
Parameters:
code - the code to generate