Package com.itextpdf.barcodes
Class BarcodePDF417
- java.lang.Object
-
- com.itextpdf.barcodes.Barcode2D
-
- com.itextpdf.barcodes.BarcodePDF417
-
public class BarcodePDF417 extends Barcode2D
PDF417 is a stacked linear barcode format used in a variety of applications such as transport, identification cards, and inventory management. "PDF" stands for Portable Data File. The "417" signifies that each pattern in the code consists of 4 bars and spaces in a pattern that is 17 units (modules) long. It is defined in ISO 15438.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BarcodePDF417.Segment
A container that encapsulates all data needed for a segment.protected static class
BarcodePDF417.SegmentList
An utility class that encapsulates a list of segments.
-
Field Summary
Fields Modifier and Type Field Description protected static int
ABSOLUTE_MAX_TEXT_SIZE
protected static int
AL
protected static int
ALPHA
protected static int
AS
private float
aspectRatio
Holds value of property aspectRatio.private int
bitColumns
Holds value of property bitColumns.protected int
bitPtr
protected static int
BYTE_MODE
protected static int
BYTE_MODE_6
protected static int
BYTESHIFT
private static int[][]
CLUSTERS
private byte[]
code
Holds value of property code.private int
codeColumns
Holds value of property codeColumns.private int
codeRows
Holds value of property codeRows.private int[]
codewords
Holds value of property codewords.protected int
cwPtr
protected static float
DEFAUL_MODULE_HEIGHT
protected static float
DEFAUL_MODULE_WIDTH
private static int[][]
ERROR_LEVEL
private int
errorLevel
Holds value of property errorLevel.protected static int
ISBYTE
private int
lenCodewords
Holds value of property lenCodewords.protected static int
LL
protected static int
LOWER
protected static int
MACRO_LAST_SEGMENT
protected static int
MACRO_SEGMENT_ID
private java.lang.String
macroFileId
private int
macroIndex
private int
macroSegmentCount
private int
macroSegmentId
protected static int
MAX_DATA_CODEWORDS
protected static int
MIXED
private static java.lang.String
MIXED_SET
protected static int
ML
protected static int
MOD
protected static int
NUMERIC_MODE
private int
options
Holds value of property options.private byte[]
outBits
Holds value of property outBits.protected static int
PAL
static int
PDF417_AUTO_ERROR_LEVEL
The error level correction is set automatically according to ISO 15438 recommendations.static int
PDF417_FIXED_COLUMNS
The size will be at leastcodeColumns
with a variable number ofcodeRows
.static int
PDF417_FIXED_RECTANGLE
The size of the barcode will be at leastcodeColumns*codeRows
.static int
PDF417_FIXED_ROWS
The size will be at leastcodeRows
with a variable number ofcodeColumns
.static int
PDF417_FORCE_BINARY
One single binary segment is usedstatic int
PDF417_INVERT_BITMAP
Inverts the output bits of the raw bitmap that is normally bit one for black.static int
PDF417_USE_ASPECT_RATIO
Auto-size is made based onaspectRatio
andyHeight
.static int
PDF417_USE_ERROR_LEVEL
The error level correction is set by the user.static int
PDF417_USE_MACRO
Use Macro PDF417 Encodingstatic int
PDF417_USE_RAW_CODEWORDS
Notext
interpretation is done and the content ofcodewords
is used directly.protected static int
PL
protected static int
PS
protected static int
PUNCTUATION
private static java.lang.String
PUNCTUATION_SET
protected BarcodePDF417.SegmentList
segmentList
protected static int
SPACE
protected static int
START_CODE_SIZE
protected static int
START_PATTERN
protected static int
STOP_PATTERN
protected static int
STOP_SIZE
protected static int
TEXT_MODE
private float
yHeight
Holds value of property yHeight.-
Fields inherited from class com.itextpdf.barcodes.Barcode2D
DEFAULT_MODULE_SIZE
-
-
Constructor Summary
Constructors Constructor Description BarcodePDF417()
Creates a newBarcodePDF417
with the default settings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
append(int in, int len)
private void
append(java.lang.String s)
protected void
assemble()
Assembles the data of the code words.private void
basicNumberCompaction(byte[] input, int start, int length)
protected void
basicNumberCompaction(int start, int length)
Compacts the codewords.(package private) void
breakString()
(package private) void
byteCompaction(int start, int length)
protected void
byteCompaction6(int start)
Compacts the code wordsprotected void
calculateErrorCorrection(int dest)
Calculates the error correction codewords.protected boolean
checkSegmentType(BarcodePDF417.Segment segment, char type)
Checks whether the segment is of a certain type.java.awt.Image
createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
.PdfFormXObject
createFormXObject(Color foreground, float moduleWidth, float moduleHeight, PdfDocument document)
Creates a PdfFormXObject with the barcode with given module width and module height.PdfFormXObject
createFormXObject(Color foreground, PdfDocument document)
Creates a PdfFormXObject with the barcode.protected void
dumpList()
Prints the segments to standard output.float
getAspectRatio()
Gets the barcode aspect ratio.Rectangle
getBarcodeSize()
Gets the maximum area that the barcode and the text, if any, will occupy.int
getBitColumns()
Gets the number of X pixels ofoutBits
.byte[]
getCode()
Gets the bytes that form the barcode.int
getCodeColumns()
Gets the number of barcode data columns.int
getCodeRows()
Gets the number of Y pixels ofoutBits
.int[]
getCodewords()
Gets the codeword array.int
getErrorLevel()
Gets the error level correction used for the barcode.int
getLenCodewords()
Gets the length of the codewords.protected int
getMaxSquare()
Calculates the max square that can contain the barcode.int
getOptions()
Gets the options to generate the barcode.byte[]
getOutBits()
Gets the raw image bits of the barcode.protected int
getSegmentLength(BarcodePDF417.Segment segment)
Calculates the length of the given segmentprivate static int
getTextTypeAndValue(byte[] input, int maxLength, int idx)
protected int
getTextTypeAndValue(int maxLength, int idx)
Gets the text type and value.float
getYHeight()
Gets the Y pixel height relative to X.private void
macroCodes()
protected static int
maxPossibleErrorLevel(int remain)
Calculates the highest error level that can be used for the remaining number of data codewords.private void
numberCompaction(byte[] input, int start, int length)
protected void
numberCompaction(int start, int length)
Compacts the code words.protected void
outCodeword(int codeword)
Utility method that adds a codeword to the barcode.protected void
outCodeword17(int codeword)
Adds the code word to the correct code word to the 17th bit.protected void
outCodeword18(int codeword)
Adds the code word to the correct code word to the 18th bit.protected void
outPaintCode()
Adds the barcode to the output bits.protected void
outStartPattern()
Adds the start pattern to the output.protected void
outStopPattern()
Adds the stop pattern to the output.void
paintCode()
Paints the barcode.Rectangle
placeBarcode(PdfCanvas canvas, Color foreground)
Places the barcode in aPdfCanvas
.Rectangle
placeBarcode(PdfCanvas canvas, Color foreground, float moduleWidth, float moduleHeight)
Places the barcode in aPdfCanvas
.void
setAspectRatio(float aspectRatio)
Sets the barcode aspect ratio.void
setCode(byte[] code)
Sets the bytes that form the barcode.void
setCode(java.lang.String text)
Sets the code that will form the barcode.void
setCodeColumns(int codeColumns)
Sets the number of barcode data columns.void
setCodeRows(int codeRows)
Sets the number of barcode rows.void
setDefaultParameters()
Set the default settings that correspond toPDF417_USE_ASPECT_RATIO
andPDF417_AUTO_ERROR_LEVEL
.void
setErrorLevel(int errorLevel)
Sets the error level correction for the barcode.void
setLenCodewords(int lenCodewords)
Sets the length of the codewords.void
setMacroFileId(java.lang.String id)
Sets the File ID for macro PDF417 encodingvoid
setMacroSegmentCount(int cnt)
Sets the segment count for macro PDF417 encodingvoid
setMacroSegmentId(int id)
Sets the segment id for macro PDF417 encodingvoid
setOptions(int options)
Sets the options to generate the barcode.void
setYHeight(float yHeight)
Sets the Y pixel height relative to X.private void
textCompaction(byte[] input, int start, int length)
protected void
textCompaction(int start, int length)
Compacts the codewords.-
Methods inherited from class com.itextpdf.barcodes.Barcode2D
createFormXObject
-
-
-
-
Field Detail
-
PDF417_USE_ASPECT_RATIO
public static final int PDF417_USE_ASPECT_RATIO
Auto-size is made based onaspectRatio
andyHeight
.- 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 leastcodeColumns
with a variable number ofcodeRows
.- See Also:
- Constant Field Values
-
PDF417_FIXED_ROWS
public static final int PDF417_FIXED_ROWS
The size will be at leastcodeRows
with 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
Notext
interpretation is done and the content ofcodewords
is 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
-
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
-
DEFAUL_MODULE_WIDTH
protected static final float DEFAUL_MODULE_WIDTH
- See Also:
- Constant Field Values
-
DEFAUL_MODULE_HEIGHT
protected static final float DEFAUL_MODULE_HEIGHT
- See Also:
- Constant Field Values
-
MIXED_SET
private static final java.lang.String MIXED_SET
- See Also:
- Constant Field Values
-
PUNCTUATION_SET
private static final java.lang.String PUNCTUATION_SET
- See Also:
- Constant Field Values
-
CLUSTERS
private static final int[][] CLUSTERS
-
ERROR_LEVEL
private static final int[][] ERROR_LEVEL
-
bitPtr
protected int bitPtr
-
cwPtr
protected int cwPtr
-
segmentList
protected BarcodePDF417.SegmentList segmentList
-
macroSegmentCount
private int macroSegmentCount
-
macroSegmentId
private int macroSegmentId
-
macroFileId
private java.lang.String macroFileId
-
macroIndex
private int macroIndex
-
outBits
private byte[] outBits
Holds value of property outBits.
-
bitColumns
private int bitColumns
Holds value of property bitColumns.
-
codeRows
private int codeRows
Holds value of property codeRows.
-
codeColumns
private int codeColumns
Holds value of property codeColumns.
-
codewords
private int[] codewords
Holds value of property codewords.
-
lenCodewords
private int lenCodewords
Holds value of property lenCodewords.
-
errorLevel
private int errorLevel
Holds value of property errorLevel.
-
code
private byte[] code
Holds value of property code.
-
options
private int options
Holds value of property options.
-
aspectRatio
private float aspectRatio
Holds value of property aspectRatio.
-
yHeight
private float yHeight
Holds value of property yHeight.
-
-
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
-
setDefaultParameters
public void setDefaultParameters()
Set the default settings that correspond toPDF417_USE_ASPECT_RATIO
andPDF417_AUTO_ERROR_LEVEL
.
-
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 classBarcode2D
- Returns:
- the size the barcode occupies.
-
placeBarcode
public Rectangle placeBarcode(PdfCanvas canvas, Color foreground)
Places the barcode in aPdfCanvas
. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.- Specified by:
placeBarcode
in classBarcode2D
- Parameters:
canvas
- thePdfCanvas
where the barcode will be placedforeground
- the foreground color. It can benull
- Returns:
- the dimensions the barcode occupies
-
placeBarcode
public Rectangle placeBarcode(PdfCanvas canvas, Color foreground, float moduleWidth, float moduleHeight)
Places the barcode in aPdfCanvas
.
-
paintCode
public void paintCode()
Paints the barcode. If no exception was thrown a valid barcode is available.
-
createFormXObject
public PdfFormXObject createFormXObject(Color foreground, PdfDocument document)
Creates a PdfFormXObject with the barcode.- Specified by:
createFormXObject
in classBarcode2D
- Parameters:
foreground
- the color of the pixels. It can benull
document
- The document- Returns:
- the XObject.
-
createFormXObject
public PdfFormXObject createFormXObject(Color foreground, float moduleWidth, float moduleHeight, PdfDocument document)
Creates a PdfFormXObject with the barcode with given module width and module height.- Parameters:
foreground
- The color of the pixels. It can benull
moduleWidth
- The width of the pixels.moduleHeight
- The height of the pixels.document
- The document- Returns:
- the XObject.
-
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_CODEWORDS
is 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
-
getCode
public byte[] getCode()
Gets the bytes that form the barcode. This bytes should be interpreted in the codepage Cp437.- Returns:
- the bytes that form the barcode
-
setCode
public void setCode(byte[] code)
Sets the bytes that form the barcode. This bytes should be interpreted in the codepage Cp437.- Parameters:
code
- the bytes that form the barcode
-
setCode
public void setCode(java.lang.String text)
Sets the code that will form the barcode. This text is converted to bytes using the encoding Cp437.- Parameters:
text
- 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
-
outCodeword17
protected void outCodeword17(int codeword)
Adds the code word to the correct code word to the 17th bit.- Parameters:
codeword
- the code word
-
outCodeword18
protected void outCodeword18(int codeword)
Adds the code word to the correct code word to the 18th bit.- Parameters:
codeword
- the code word
-
outCodeword
protected void outCodeword(int codeword)
Utility method that adds a codeword to the barcode.- Parameters:
codeword
- the codeword to add
-
outStopPattern
protected void outStopPattern()
Adds the stop pattern to the output.
-
outStartPattern
protected void outStartPattern()
Adds the start pattern to the output.
-
outPaintCode
protected void outPaintCode()
Adds the barcode to the output bits.
-
calculateErrorCorrection
protected void calculateErrorCorrection(int dest)
Calculates the error correction codewords.- Parameters:
dest
- length of the code words
-
textCompaction
protected void textCompaction(int start, int length)
Compacts the codewords.- Parameters:
start
- the start positionlength
- the length
-
basicNumberCompaction
protected void basicNumberCompaction(int start, int length)
Compacts the codewords.- Parameters:
start
- the start positionlength
- the length
-
getTextTypeAndValue
protected int getTextTypeAndValue(int maxLength, int idx)
Gets the text type and value.- Parameters:
maxLength
- the maximum lengthidx
- the index- Returns:
- the text type and value
-
checkSegmentType
protected boolean checkSegmentType(BarcodePDF417.Segment segment, char type)
Checks whether the segment is of a certain type.- Parameters:
segment
- the segment to checktype
- the type to check against- Returns:
- true if the segment is of the specified type
-
getSegmentLength
protected int getSegmentLength(BarcodePDF417.Segment segment)
Calculates the length of the given segment- Parameters:
segment
- the segment to check- Returns:
- the length of the segment
-
numberCompaction
protected void numberCompaction(int start, int length)
Compacts the code words.- Parameters:
start
- the start positionlength
- the length
-
byteCompaction6
protected void byteCompaction6(int start)
Compacts the code words- Parameters:
start
- the start position
-
assemble
protected void assemble()
Assembles the data of the code words.
-
maxPossibleErrorLevel
protected static int maxPossibleErrorLevel(int remain)
Calculates the highest error level that can be used for the remaining number of data codewords.- Parameters:
remain
- the number of data codewords- Returns:
- the highest error level that can be used
-
dumpList
protected void dumpList()
Prints the segments to standard output.
-
getMaxSquare
protected int getMaxSquare()
Calculates the max square that can contain the barcode. And sets the codeColumns and codeRows variables.- Returns:
- the max square that can contain the barcode
-
byteCompaction
void byteCompaction(int start, int length)
-
breakString
void breakString()
-
basicNumberCompaction
private void basicNumberCompaction(byte[] input, int start, int length)
-
numberCompaction
private void numberCompaction(byte[] input, int start, int length)
-
macroCodes
private void macroCodes()
-
append
private void append(int in, int len)
-
append
private void append(java.lang.String s)
-
getTextTypeAndValue
private static int getTextTypeAndValue(byte[] input, int maxLength, int idx)
-
textCompaction
private void textCompaction(byte[] input, int start, int length)
-
-