Package com.itextpdf.text.pdf
Class Barcode128
- java.lang.Object
-
- com.itextpdf.text.pdf.Barcode
-
- com.itextpdf.text.pdf.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:
- CODE128 - plain barcode 128.
- CODE128_UCC - support for UCC/EAN-128 with a full list of AI.
- CODE128_RAW - raw mode. The code attribute has the actual codes from 0 to 105 followed by '\uffff' and the human readable text.
x = 0.8f; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; codeType = CODE128;
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Barcode128.Barcode128CodeSet
-
Field Summary
Fields Modifier and Type Field Description private static IntHashtable
ais
private static byte[][]
BARS
The bars to generate the code.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
private Barcode128.Barcode128CodeSet
codeSet
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
START_A
The start code.static char
START_B
The start code.static char
START_C
The start code.static char
STARTA
static char
STARTB
static char
STARTC
-
Fields inherited from class com.itextpdf.text.pdf.Barcode
altText, barHeight, baseline, checksumText, CODABAR, code, CODE128, CODE128_RAW, CODE128_UCC, codeType, EAN13, EAN8, extended, font, generateChecksum, guardBars, inkSpreading, n, PLANET, POSTNET, size, startStopText, SUPP2, SUPP5, textAlignment, UPCA, UPCE, x
-
-
Constructor Summary
Constructors Constructor Description Barcode128()
Creates new Barcode128
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Image
createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
.Rectangle
getBarcodeSize()
Gets the maximum area that the barcode and the text, if any, will occupy.static byte[]
getBarsCode128Raw(java.lang.String text)
Generates the bars.Barcode128.Barcode128CodeSet
getCodeSet()
static java.lang.String
getHumanReadableUCCEAN(java.lang.String code)
Gets the human readable text of a sequence of AI.(package private) static java.lang.String
getPackedRawDigits(java.lang.String text, int textIndex, int numDigits)
Packs the digits for charset C also considering FNC1.static java.lang.String
getRawText(java.lang.String text, boolean ucc)
Converts the human readable text to the characters needed to create a barcode.static java.lang.String
getRawText(java.lang.String text, boolean ucc, Barcode128.Barcode128CodeSet codeSet)
Converts the human readable text to the characters needed to create a barcode using the specified code set.(package private) static boolean
isNextDigits(java.lang.String text, int textIndex, int numDigits)
Returnstrue
if the nextnumDigits
starting from indextextIndex
are numeric skipping any FNC1.Rectangle
placeBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
Places the barcode in aPdfContentByte
.static java.lang.String
removeFNC1(java.lang.String code)
Removes the FNC1 codes in the text.void
setCode(java.lang.String code)
Sets the code to generate.void
setCodeSet(Barcode128.Barcode128CodeSet codeSet)
-
Methods inherited from class com.itextpdf.text.pdf.Barcode
createImageWithBarcode, createTemplateWithBarcode, getAltText, getBarHeight, getBaseline, getCode, getCodeType, getFont, getInkSpreading, getN, getSize, getTextAlignment, getX, isChecksumText, isExtended, isGenerateChecksum, isGuardBars, isStartStopText, setAltText, setBarHeight, setBaseline, setChecksumText, setCodeType, setExtended, setFont, setGenerateChecksum, setGuardBars, setInkSpreading, setN, setSize, setStartStopText, setTextAlignment, setX
-
-
-
-
Field Detail
-
BARS
private static final byte[][] BARS
The bars to generate the code.
-
BARS_STOP
private static final byte[] BARS_STOP
The stop bars.
-
CODE_AB_TO_C
public static final char CODE_AB_TO_C
The charset code change.- See Also:
- Constant Field Values
-
CODE_AC_TO_B
public static final char CODE_AC_TO_B
The charset code change.- See Also:
- Constant Field Values
-
CODE_BC_TO_A
public static final char CODE_BC_TO_A
The charset code change.- See Also:
- Constant Field Values
-
FNC1_INDEX
public static final char FNC1_INDEX
The code for UCC/EAN-128.- See Also:
- Constant Field Values
-
START_A
public static final char START_A
The start code.- See Also:
- Constant Field Values
-
START_B
public static final char START_B
The start code.- See Also:
- Constant Field Values
-
START_C
public static final char START_C
The start code.- See Also:
- Constant Field Values
-
FNC1
public static final char FNC1
- See Also:
- Constant Field Values
-
DEL
public static final char DEL
- See Also:
- Constant Field Values
-
FNC3
public static final char FNC3
- See Also:
- Constant Field Values
-
FNC2
public static final char FNC2
- See Also:
- Constant Field Values
-
SHIFT
public static final char SHIFT
- See Also:
- Constant Field Values
-
CODE_C
public static final char CODE_C
- See Also:
- Constant Field Values
-
CODE_A
public static final char CODE_A
- See Also:
- Constant Field Values
-
FNC4
public static final char FNC4
- See Also:
- Constant Field Values
-
STARTA
public static final char STARTA
- See Also:
- Constant Field Values
-
STARTB
public static final char STARTB
- See Also:
- Constant Field Values
-
STARTC
public static final char STARTC
- See Also:
- Constant Field Values
-
ais
private static final IntHashtable ais
-
codeSet
private Barcode128.Barcode128CodeSet codeSet
-
-
Method Detail
-
setCodeSet
public void setCodeSet(Barcode128.Barcode128CodeSet codeSet)
-
getCodeSet
public Barcode128.Barcode128CodeSet getCodeSet()
-
removeFNC1
public static java.lang.String removeFNC1(java.lang.String code)
Removes the FNC1 codes in the text.- Parameters:
code
- the text to clean- Returns:
- the cleaned text
-
getHumanReadableUCCEAN
public static java.lang.String getHumanReadableUCCEAN(java.lang.String code)
Gets the human readable text of a sequence of AI.- Parameters:
code
- the text- Returns:
- the human readable text
-
isNextDigits
static boolean isNextDigits(java.lang.String text, int textIndex, int numDigits)
Returnstrue
if the nextnumDigits
starting from indextextIndex
are numeric skipping any FNC1.- Parameters:
text
- the text to checktextIndex
- where to check fromnumDigits
- the number of digits to check- Returns:
- the check result
-
getPackedRawDigits
static java.lang.String getPackedRawDigits(java.lang.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 packtextIndex
- where to pack fromnumDigits
- the number of digits to pack. It is always an even number- Returns:
- the packed digits, two digits per character
-
getRawText
public static java.lang.String getRawText(java.lang.String text, boolean ucc, Barcode128.Barcode128CodeSet codeSet)
Converts the human readable text to the characters needed to create a barcode using the specified code set.- Parameters:
text
- the text to convertucc
-true
if it is an UCC/EAN-128. In this case the character FNC1 is addedcodeSet
- forced code set, or AUTO for optimized barcode.- Returns:
- the code ready to be fed to getBarsCode128Raw()
-
getRawText
public static java.lang.String getRawText(java.lang.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 convertucc
-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()
-
getBarsCode128Raw
public static byte[] getBarsCode128Raw(java.lang.String text)
Generates the bars. The input has the actual barcodes, not the human readable text.- Parameters:
text
- the barcode- Returns:
- the bars
-
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).- Specified by:
getBarcodeSize
in classBarcode
- Returns:
- the size the barcode occupies.
-
placeBarcode
public Rectangle placeBarcode(PdfContentByte cb, BaseColor barColor, BaseColor textColor)
Places the barcode in aPdfContentByte
. The barcode is always placed at coordinates (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 withtextColor
barColor
textColor
bars painted with
barColor
text painted withtextColor
- Specified by:
placeBarcode
in classBarcode
- Parameters:
cb
- thePdfContentByte
where the barcode will be placedbarColor
- the color of the bars. It can benull
textColor
- the color of the text. It can benull
- Returns:
- the dimensions the barcode occupies
-
setCode
public void setCode(java.lang.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
-
createAwtImage
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
. This image only contains the bars without any text.- Specified by:
createAwtImage
in classBarcode
- Parameters:
foreground
- the color of the barsbackground
- the color of the background- Returns:
- the image
-
-