Package com.itextpdf.barcodes
Class Barcode128
- java.lang.Object
-
- com.itextpdf.barcodes.Barcode1D
-
- com.itextpdf.barcodes.Barcode128
-
public class Barcode128 extends Barcode1D
BarCode 128 is a high-density linear barcode symbology defined in ISO/IEC 15417:2007. It is used for alphanumeric or numeric-only barcodes. It can encode all 128 characters of ASCII
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Barcode128.Barcode128CodeSet
The code set to be used to start encoding.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.Integer,java.lang.Integer>
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
static int
CODE128
A type of barcodestatic int
CODE128_RAW
A type of barcodestatic int
CODE128_UCC
A type of barcodeprivate 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.barcodes.Barcode1D
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, altText, barHeight, baseline, checksumText, code, codeType, DEFAULT_BAR_BACKGROUND_COLOR, DEFAULT_BAR_FOREGROUND_COLOR, document, extended, font, generateChecksum, guardBars, inkSpreading, n, size, startStopText, textAlignment, x
-
-
Constructor Summary
Constructors Constructor Description Barcode128(PdfDocument document)
Creates new Barcode128.Barcode128(PdfDocument document, PdfFont font)
Creates new Barcode128, which will use the provided font
-
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()
Get the code set that is used.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.private static char
getStartSymbol(Barcode128.Barcode128CodeSet codeSet)
(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(PdfCanvas canvas, Color barColor, Color textColor)
Places the barcode in aPdfCanvas
.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)
Sets the code set to use.-
Methods inherited from class com.itextpdf.barcodes.Barcode1D
createFormXObject, createFormXObject, fitWidth, getAltText, getBarHeight, getBaseline, getCode, getCodeType, getDescender, 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
-
CODE128
public static final int CODE128
A type of barcode- See Also:
- Constant Field Values
-
CODE128_UCC
public static final int CODE128_UCC
A type of barcode- See Also:
- Constant Field Values
-
CODE128_RAW
public static final int CODE128_RAW
A type of barcode- See Also:
- Constant Field Values
-
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 java.util.Map<java.lang.Integer,java.lang.Integer> ais
-
codeSet
private Barcode128.Barcode128CodeSet codeSet
-
-
Constructor Detail
-
Barcode128
public Barcode128(PdfDocument document)
Creates new Barcode128. To generate the font thePdfDocument.getDefaultFont()
will be implicitly called. If you want to use this barcode in PDF/A documents, please consider usingBarcode128(PdfDocument, PdfFont)
.- Parameters:
document
- The document to which the barcode will be added
-
Barcode128
public Barcode128(PdfDocument document, PdfFont font)
Creates new Barcode128, which will use the provided font- Parameters:
document
- The document to which the barcode will be addedfont
- The font to use
-
-
Method Detail
-
setCodeSet
public void setCodeSet(Barcode128.Barcode128CodeSet codeSet)
Sets the code set to use.- Parameters:
codeSet
- the code set to use.
-
getCodeSet
public Barcode128.Barcode128CodeSet getCodeSet()
Get the code set that is used.- Returns:
- the code set.
-
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
-
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 classBarcode1D
- Returns:
- the size the barcode occupies.
-
placeBarcode
public Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor)
Places the barcode in aPdfCanvas
. 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 classBarcode1D
- Parameters:
canvas
- thePdfCanvas
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 classBarcode1D
- Parameters:
foreground
- the color of the barsbackground
- the color of the background- Returns:
- the image
-
getStartSymbol
private static char getStartSymbol(Barcode128.Barcode128CodeSet codeSet)
-
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
-
-