- java.lang.Object
-
- com.itextpdf.text.pdf.BarcodePDF417
-
public class BarcodePDF417 extends java.lang.ObjectGenerates the 2D barcode PDF417. Supports dimensioning auto-sizing, fixed and variable sizes, automatic and manual error levels, raw codeword input, codeword size optimization and bitmap inversion. The output can be a CCITT G4Imageor a raw bitmap.- Author:
- Paulo Soares (psoares@consiste.pt)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBarcodePDF417.Segmentprotected static classBarcodePDF417.SegmentList
-
Field Summary
Fields Modifier and Type Field Description protected static intABSOLUTE_MAX_TEXT_SIZEprotected static intALprotected static intALPHAprotected static intASprotected intbitPtrprotected static intBYTE_MODEprotected static intBYTE_MODE_6protected static intBYTESHIFTprotected intcwPtrprotected static intISBYTEprotected static intLLprotected static intLOWERprotected static intMACRO_LAST_SEGMENTprotected static intMACRO_SEGMENT_IDprotected static intMAX_DATA_CODEWORDSprotected static intMIXEDprotected static intMLprotected static intMODprotected static intNUMERIC_MODEprotected static intPALstatic intPDF417_AUTO_ERROR_LEVELThe error level correction is set automatically according to ISO 15438 recommendations.static intPDF417_FIXED_COLUMNSThe size will be at leastcodeColumnswith a variable number ofcodeRows.static intPDF417_FIXED_RECTANGLEThe size of the barcode will be at leastcodeColumns*codeRows.static intPDF417_FIXED_ROWSThe size will be at leastcodeRowswith a variable number ofcodeColumns.static intPDF417_FORCE_BINARYOne single binary segment is usedstatic intPDF417_INVERT_BITMAPInverts the output bits of the raw bitmap that is normally bit one for black.static intPDF417_USE_ASPECT_RATIOAuto-size is made based onaspectRatioandyHeight.static intPDF417_USE_ERROR_LEVELThe error level correction is set by the user.static intPDF417_USE_MACROUse Macro PDF417 Encodingstatic intPDF417_USE_RAW_CODEWORDSNotextinterpretation is done and the content ofcodewordsis used directly.protected static intPLprotected static intPSprotected static intPUNCTUATIONprotected BarcodePDF417.SegmentListsegmentListprotected static intSPACEprotected static intSTART_CODE_SIZEprotected static intSTART_PATTERNprotected static intSTOP_PATTERNprotected static intSTOP_SIZEprotected static intTEXT_MODE
-
Constructor Summary
Constructors Constructor Description BarcodePDF417()Creates a newBarcodePDF417with the default settings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassemble()protected voidbasicNumberCompaction(int start, int length)protected voidbyteCompaction6(int start)protected voidcalculateErrorCorrection(int dest)protected booleancheckSegmentType(BarcodePDF417.Segment segment, char type)java.awt.ImagecreateAwtImage(java.awt.Color foreground, java.awt.Color background)Creates ajava.awt.Image.protected voiddumpList()floatgetAspectRatio()Gets the barcode aspect ratio.intgetBitColumns()Gets the number of X pixels ofoutBits.intgetCodeColumns()Gets the number of barcode data columns.intgetCodeRows()Gets the number of Y pixels ofoutBits.int[]getCodewords()Gets the codeword array.intgetErrorLevel()Gets the error level correction used for the barcode.ImagegetImage()Gets anImagewith the barcode.intgetLenCodewords()Gets the length of the codewords.protected intgetMaxSquare()intgetOptions()Gets the options to generate the barcode.byte[]getOutBits()Gets the raw image bits of the barcode.protected intgetSegmentLength(BarcodePDF417.Segment segment)byte[]getText()Gets the bytes that form the barcode.protected intgetTextTypeAndValue(int maxLength, int idx)floatgetYHeight()Gets the Y pixel height relative to X.protected static intmaxPossibleErrorLevel(int remain)protected voidnumberCompaction(int start, int length)protected voidoutCodeword(int codeword)protected voidoutCodeword17(int codeword)protected voidoutCodeword18(int codeword)protected voidoutPaintCode()protected voidoutStartPattern()protected voidoutStopPattern()voidpaintCode()Paints the barcode.voidsetAspectRatio(float aspectRatio)Sets the barcode aspect ratio.voidsetCodeColumns(int codeColumns)Sets the number of barcode data columns.voidsetCodeRows(int codeRows)Sets the number of barcode rows.voidsetDefaultParameters()Set the default settings that correspond toPDF417_USE_ASPECT_RATIOandPDF417_AUTO_ERROR_LEVEL.voidsetErrorLevel(int errorLevel)Sets the error level correction for the barcode.voidsetLenCodewords(int lenCodewords)Sets the length of the codewords.voidsetMacroFileId(java.lang.String id)Sets the File ID for macro PDF417 encodingvoidsetMacroSegmentCount(int cnt)Sets the segment count for macro PDF417 encodingvoidsetMacroSegmentId(int id)Sets the segment id for macro PDF417 encodingvoidsetOptions(int options)Sets the options to generate the barcode.voidsetText(byte[] text)Sets the bytes that form the barcode.voidsetText(java.lang.String s)Sets the text that will form the barcode.voidsetYHeight(float yHeight)Sets the Y pixel height relative to X.protected voidtextCompaction(int start, int length)
-
-
-
Field Detail
-
PDF417_USE_ASPECT_RATIO
public static final int PDF417_USE_ASPECT_RATIO
Auto-size is made based onaspectRatioandyHeight.- See Also:
- Constant Field Values
-
PDF417_FIXED_RECTANGLE
public static final int PDF417_FIXED_RECTANGLE
The size of the barcode will be at leastcodeColumns*codeRows.- See Also:
- Constant Field Values
-
PDF417_FIXED_COLUMNS
public static final int PDF417_FIXED_COLUMNS
The size will be at leastcodeColumnswith a variable number ofcodeRows.- See Also:
- Constant Field Values
-
PDF417_FIXED_ROWS
public static final int PDF417_FIXED_ROWS
The size will be at leastcodeRowswith a variable number ofcodeColumns.- See Also:
- Constant Field Values
-
PDF417_AUTO_ERROR_LEVEL
public static final int PDF417_AUTO_ERROR_LEVEL
The error level correction is set automatically according to ISO 15438 recommendations.- See Also:
- Constant Field Values
-
PDF417_USE_ERROR_LEVEL
public static final int PDF417_USE_ERROR_LEVEL
The error level correction is set by the user. It can be 0 to 8.- See Also:
- Constant Field Values
-
PDF417_FORCE_BINARY
public static final int PDF417_FORCE_BINARY
One single binary segment is used- See Also:
- Constant Field Values
-
PDF417_USE_RAW_CODEWORDS
public static final int PDF417_USE_RAW_CODEWORDS
Notextinterpretation is done and the content ofcodewordsis used directly.- See Also:
- Constant Field Values
-
PDF417_INVERT_BITMAP
public static final int PDF417_INVERT_BITMAP
Inverts the output bits of the raw bitmap that is normally bit one for black. It has only effect for the raw bitmap.- See Also:
- Constant Field Values
-
PDF417_USE_MACRO
public static final int PDF417_USE_MACRO
Use Macro PDF417 Encoding
-
bitPtr
protected int bitPtr
-
cwPtr
protected int cwPtr
-
segmentList
protected BarcodePDF417.SegmentList segmentList
-
START_PATTERN
protected static final int START_PATTERN
- See Also:
- Constant Field Values
-
STOP_PATTERN
protected static final int STOP_PATTERN
- See Also:
- Constant Field Values
-
START_CODE_SIZE
protected static final int START_CODE_SIZE
- See Also:
- Constant Field Values
-
STOP_SIZE
protected static final int STOP_SIZE
- See Also:
- Constant Field Values
-
MOD
protected static final int MOD
- See Also:
- Constant Field Values
-
ALPHA
protected static final int ALPHA
- See Also:
- Constant Field Values
-
LOWER
protected static final int LOWER
- See Also:
- Constant Field Values
-
MIXED
protected static final int MIXED
- See Also:
- Constant Field Values
-
PUNCTUATION
protected static final int PUNCTUATION
- See Also:
- Constant Field Values
-
ISBYTE
protected static final int ISBYTE
- See Also:
- Constant Field Values
-
BYTESHIFT
protected static final int BYTESHIFT
- See Also:
- Constant Field Values
-
PL
protected static final int PL
- See Also:
- Constant Field Values
-
LL
protected static final int LL
- See Also:
- Constant Field Values
-
AS
protected static final int AS
- See Also:
- Constant Field Values
-
ML
protected static final int ML
- See Also:
- Constant Field Values
-
AL
protected static final int AL
- See Also:
- Constant Field Values
-
PS
protected static final int PS
- See Also:
- Constant Field Values
-
PAL
protected static final int PAL
- See Also:
- Constant Field Values
-
SPACE
protected static final int SPACE
- See Also:
- Constant Field Values
-
TEXT_MODE
protected static final int TEXT_MODE
- See Also:
- Constant Field Values
-
BYTE_MODE_6
protected static final int BYTE_MODE_6
- See Also:
- Constant Field Values
-
BYTE_MODE
protected static final int BYTE_MODE
- See Also:
- Constant Field Values
-
NUMERIC_MODE
protected static final int NUMERIC_MODE
- See Also:
- Constant Field Values
-
ABSOLUTE_MAX_TEXT_SIZE
protected static final int ABSOLUTE_MAX_TEXT_SIZE
- See Also:
- Constant Field Values
-
MAX_DATA_CODEWORDS
protected static final int MAX_DATA_CODEWORDS
- See Also:
- Constant Field Values
-
MACRO_SEGMENT_ID
protected static final int MACRO_SEGMENT_ID
- See Also:
- Constant Field Values
-
MACRO_LAST_SEGMENT
protected static final int MACRO_LAST_SEGMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setMacroSegmentId
public void setMacroSegmentId(int id)
Sets the segment id for macro PDF417 encoding- Parameters:
id- the id (starting at 0)- See Also:
setMacroSegmentCount(int)
-
setMacroSegmentCount
public void setMacroSegmentCount(int cnt)
Sets the segment count for macro PDF417 encoding- Parameters:
cnt- the number of macro segments- See Also:
setMacroSegmentId(int)
-
setMacroFileId
public void setMacroFileId(java.lang.String id)
Sets the File ID for macro PDF417 encoding- Parameters:
id- the file id
-
checkSegmentType
protected boolean checkSegmentType(BarcodePDF417.Segment segment, char type)
-
getSegmentLength
protected int getSegmentLength(BarcodePDF417.Segment segment)
-
setDefaultParameters
public void setDefaultParameters()
Set the default settings that correspond toPDF417_USE_ASPECT_RATIOandPDF417_AUTO_ERROR_LEVEL.
-
outCodeword17
protected void outCodeword17(int codeword)
-
outCodeword18
protected void outCodeword18(int codeword)
-
outCodeword
protected void outCodeword(int codeword)
-
outStopPattern
protected void outStopPattern()
-
outStartPattern
protected void outStartPattern()
-
outPaintCode
protected void outPaintCode()
-
calculateErrorCorrection
protected void calculateErrorCorrection(int dest)
-
getTextTypeAndValue
protected int getTextTypeAndValue(int maxLength, int idx)
-
textCompaction
protected void textCompaction(int start, int length)
-
basicNumberCompaction
protected void basicNumberCompaction(int start, int length)
-
numberCompaction
protected void numberCompaction(int start, int length)
-
byteCompaction6
protected void byteCompaction6(int start)
-
assemble
protected void assemble()
-
maxPossibleErrorLevel
protected static int maxPossibleErrorLevel(int remain)
-
dumpList
protected void dumpList()
-
getMaxSquare
protected int getMaxSquare()
-
paintCode
public void paintCode()
Paints the barcode. If no exception was thrown a valid barcode is available.
-
getImage
public Image getImage() throws BadElementException
Gets anImagewith the barcode. The image will have to be scaled in the Y direction byyHeightfor the barcode to have the right printing aspect.- Returns:
- the barcode
Image - Throws:
BadElementException- on error
-
createAwtImage
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background)Creates ajava.awt.Image.- Parameters:
foreground- the color of the barsbackground- the color of the background- Returns:
- the image
-
getOutBits
public byte[] getOutBits()
Gets the raw image bits of the barcode. The image will have to be scaled in the Y direction byyHeight.- Returns:
- The raw barcode image
-
getBitColumns
public int getBitColumns()
Gets the number of X pixels ofoutBits.- Returns:
- the number of X pixels of
outBits
-
getCodeRows
public int getCodeRows()
Gets the number of Y pixels ofoutBits. It is also the number of rows in the barcode.- Returns:
- the number of Y pixels of
outBits
-
setCodeRows
public void setCodeRows(int codeRows)
Sets the number of barcode rows. This number may be changed to keep the barcode valid.- Parameters:
codeRows- the number of barcode rows
-
getCodeColumns
public int getCodeColumns()
Gets the number of barcode data columns.- Returns:
- he number of barcode data columns
-
setCodeColumns
public void setCodeColumns(int codeColumns)
Sets the number of barcode data columns. This number may be changed to keep the barcode valid.- Parameters:
codeColumns- the number of barcode data columns
-
getCodewords
public int[] getCodewords()
Gets the codeword array. This array is always 928 elements long. It can be written to if the optionPDF417_USE_RAW_CODEWORDSis set.- Returns:
- the codeword array
-
getLenCodewords
public int getLenCodewords()
Gets the length of the codewords.- Returns:
- the length of the codewords
-
setLenCodewords
public void setLenCodewords(int lenCodewords)
Sets the length of the codewords.- Parameters:
lenCodewords- the length of the codewords
-
getErrorLevel
public int getErrorLevel()
Gets the error level correction used for the barcode. It may different from the previously set value.- Returns:
- the error level correction used for the barcode
-
setErrorLevel
public void setErrorLevel(int errorLevel)
Sets the error level correction for the barcode.- Parameters:
errorLevel- the error level correction for the barcode
-
getText
public byte[] getText()
Gets the bytes that form the barcode. This bytes should be interpreted in the codepage Cp437.- Returns:
- the bytes that form the barcode
-
setText
public void setText(byte[] text)
Sets the bytes that form the barcode. This bytes should be interpreted in the codepage Cp437.- Parameters:
text- the bytes that form the barcode
-
setText
public void setText(java.lang.String s)
Sets the text that will form the barcode. This text is converted to bytes using the encoding Cp437.- Parameters:
s- the text that will form the barcode
-
getOptions
public int getOptions()
Gets the options to generate the barcode.- Returns:
- the options to generate the barcode
-
setOptions
public void setOptions(int options)
Sets the options to generate the barcode. This can be all thePDF417_*constants.- Parameters:
options- the options to generate the barcode
-
getAspectRatio
public float getAspectRatio()
Gets the barcode aspect ratio.- Returns:
- the barcode aspect ratio
-
setAspectRatio
public void setAspectRatio(float aspectRatio)
Sets the barcode aspect ratio. A ratio or 0.5 will make the barcode width twice as large as the height.- Parameters:
aspectRatio- the barcode aspect ratio
-
getYHeight
public float getYHeight()
Gets the Y pixel height relative to X.- Returns:
- the Y pixel height relative to X
-
setYHeight
public void setYHeight(float yHeight)
Sets the Y pixel height relative to X. It is usually 3.- Parameters:
yHeight- the Y pixel height relative to X
-
-