- 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;- Author:
- Paulo Soares (psoares@consiste.pt)
-
-
Field Summary
Fields Modifier and Type Field Description static charCODE_Astatic charCODE_AB_TO_CThe charset code change.static charCODE_AC_TO_BThe charset code change.static charCODE_BC_TO_AThe charset code change.static charCODE_Cstatic charDELstatic charFNC1static charFNC1_INDEXThe code for UCC/EAN-128.static charFNC2static charFNC3static charFNC4static charSHIFTstatic charSTART_AThe start code.static charSTART_BThe start code.static charSTART_CThe start code.static charSTARTAstatic charSTARTBstatic charSTARTC-
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.ImagecreateAwtImage(java.awt.Color foreground, java.awt.Color background)Creates ajava.awt.Image.RectanglegetBarcodeSize()Gets the maximum area that the barcode and the text, if any, will occupy.static byte[]getBarsCode128Raw(java.lang.String text)Generates the bars.static java.lang.StringgetHumanReadableUCCEAN(java.lang.String code)Gets the human readable text of a sequence of AI.static java.lang.StringgetRawText(java.lang.String text, boolean ucc)Converts the human readable text to the characters needed to create a barcode.RectangleplaceBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color textColor)Places the barcode in aPdfContentByte.static java.lang.StringremoveFNC1(java.lang.String code)Removes the FNC1 codes in the text.voidsetCode(java.lang.String code)Sets the code to generate.-
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
-
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
-
-
Method Detail
-
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)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-trueif 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:
getBarcodeSizein classBarcode- Returns:
- the size the barcode occupies.
-
placeBarcode
public Rectangle placeBarcode(PdfContentByte cb, java.awt.Color barColor, java.awt.Color 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:
barColortextColorResult
nullnullbars and text painted with current fill color
barColornullbars and text painted with
barColornulltextColorbars painted with current color
text painted withtextColorbarColortextColorbars painted with
barColor
text painted withtextColor- Specified by:
placeBarcodein classBarcode- Parameters:
cb- thePdfContentBytewhere the barcode will be placedbarColor- the color of the bars. It can benulltextColor- the color of the text. It can benull- Returns:
- the dimensions the barcode occupies
-
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:
createAwtImagein classBarcode- Parameters:
foreground- the color of the barsbackground- the color of the background- Returns:
- the image
-
-