com.lowagie.text.pdf

Class BarcodePDF417

public class BarcodePDF417 extends Object

Generates 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 G4 Image or a raw bitmap.

Author: Paulo Soares (psoares@consiste.pt)

Nested Class Summary
protected static classBarcodePDF417.Segment
protected static classBarcodePDF417.SegmentList
Field Summary
protected static intABSOLUTE_MAX_TEXT_SIZE
protected static intAL
protected static intALPHA
protected static intAS
floataspectRatio
Holds value of property aspectRatio.
intbitColumns
Holds value of property bitColumns.
protected intbitPtr
protected static intBYTESHIFT
protected static intBYTE_MODE
protected static intBYTE_MODE_6
intcodeColumns
Holds value of property codeColumns.
intcodeRows
Holds value of property codeRows.
int[]codewords
Holds value of property codewords.
protected intcwPtr
static int[][]CLUSTERS
interrorLevel
Holds value of property errorLevel.
static int[][]ERROR_LEVEL
protected static intISBYTE
intlenCodewords
Holds value of property lenCodewords.
protected static intLL
protected static intLOWER
StringmacroFileId
intmacroSegmentCount
intmacroSegmentId
protected static intMACRO_LAST_SEGMENT
protected static intMACRO_SEGMENT_COUNT
protected static intMACRO_SEGMENT_ID
protected static intMAX_DATA_CODEWORDS
protected static intMIXED
static StringMIXED_SET
protected static intML
protected static intMOD
protected static intNUMERIC_MODE
intoptions
Holds value of property options.
byte[]outBits
Holds value of property outBits.
protected static intPAL
static intPDF417_AUTO_ERROR_LEVEL
The error level correction is set automatically according to ISO 15438 recomendations.
static intPDF417_FIXED_COLUMNS
The size will be at least codeColumns with a variable number of codeRows.
static intPDF417_FIXED_RECTANGLE
The size of the barcode will be at least codeColumns*codeRows.
static intPDF417_FIXED_ROWS
The size will be at least codeRows with a variable number of codeColumns.
static intPDF417_FORCE_BINARY
One single binary segment is used
static intPDF417_INVERT_BITMAP
Inverts the output bits of the raw bitmap that is normally bit one for black.
static intPDF417_USE_ASPECT_RATIO
Auto-size is made based on aspectRatio and yHeight.
static intPDF417_USE_ERROR_LEVEL
The error level correction is set by the user.
static intPDF417_USE_MACRO
Use Macro PDF417 Encoding
static intPDF417_USE_RAW_CODEWORDS
No text interpretation is done and the content of codewords is used directly.
protected static intPL
protected static intPS
protected static intPUNCTUATION
static StringPUNCTUATION_SET
protected BarcodePDF417.SegmentListsegmentList
protected static intSPACE
protected static intSTART_CODE_SIZE
protected static intSTART_PATTERN
protected static intSTOP_PATTERN
protected static intSTOP_SIZE
byte[]text
Holds value of property text.
protected static intTEXT_MODE
floatyHeight
Holds value of property yHeight.
Constructor Summary
BarcodePDF417()
Creates a new BarcodePDF417 with the default settings.
Method Summary
voidappend(int in, int len)
voidappend(String s)
protected voidassemble()
protected voidbasicNumberCompaction(int start, int length)
voidbasicNumberCompaction(byte[] input, int start, int length)
voidbreakString()
voidbyteCompaction(int start, int length)
protected voidbyteCompaction6(int start)
protected voidcalculateErrorCorrection(int dest)
protected booleancheckSegmentType(BarcodePDF417.Segment segment, char type)
ImagecreateAwtImage(Color foreground, Color background)
Creates a java.awt.Image.
protected voiddumpList()
floatgetAspectRatio()
Gets the barcode aspect ratio.
intgetBitColumns()
Gets the number of X pixels of outBits.
intgetCodeColumns()
Gets the number of barcode data columns.
intgetCodeRows()
Gets the number of Y pixels of outBits.
int[]getCodewords()
Gets the codeword array.
intgetErrorLevel()
Gets the error level correction used for the barcode.
ImagegetImage()
Gets an Image with 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.
static intgetTextTypeAndValue(byte[] input, int maxLength, int idx)
protected intgetTextTypeAndValue(int maxLength, int idx)
floatgetYHeight()
Gets the Y pixel height relative to X.
voidmacroCodes()
protected static intmaxPossibleErrorLevel(int remain)
voidnumberCompaction(byte[] input, int start, int length)
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 to PDF417_USE_ASPECT_RATIO and PDF417_AUTO_ERROR_LEVEL.
voidsetErrorLevel(int errorLevel)
Sets the error level correction for the barcode.
voidsetLenCodewords(int lenCodewords)
Sets the length of the codewords.
voidsetMacroFileId(String id)
Sets the File ID for macro PDF417 encoding
voidsetMacroSegmentCount(int cnt)
Sets the segment count for macro PDF417 encoding
voidsetMacroSegmentId(int id)
Sets the segment id for macro PDF417 encoding
voidsetOptions(int options)
Sets the options to generate the barcode.
voidsetText(byte[] text)
Sets the bytes that form the barcode.
voidsetText(String s)
Sets the text that will form the barcode.
voidsetYHeight(float yHeight)
Sets the Y pixel height relative to X.
voidtextCompaction(byte[] input, int start, int length)
protected voidtextCompaction(int start, int length)

Field Detail

ABSOLUTE_MAX_TEXT_SIZE

protected static final int ABSOLUTE_MAX_TEXT_SIZE

AL

protected static final int AL

ALPHA

protected static final int ALPHA

AS

protected static final int AS

aspectRatio

private float aspectRatio
Holds value of property aspectRatio.

bitColumns

private int bitColumns
Holds value of property bitColumns.

bitPtr

protected int bitPtr

BYTESHIFT

protected static final int BYTESHIFT

BYTE_MODE

protected static final int BYTE_MODE

BYTE_MODE_6

protected static final int BYTE_MODE_6

codeColumns

private int codeColumns
Holds value of property codeColumns.

codeRows

private int codeRows
Holds value of property codeRows.

codewords

private int[] codewords
Holds value of property codewords.

cwPtr

protected int cwPtr

CLUSTERS

private static final int[][] CLUSTERS

errorLevel

private int errorLevel
Holds value of property errorLevel.

ERROR_LEVEL

private static final int[][] ERROR_LEVEL

ISBYTE

protected static final int ISBYTE

lenCodewords

private int lenCodewords
Holds value of property lenCodewords.

LL

protected static final int LL

LOWER

protected static final int LOWER

macroFileId

private String macroFileId

macroSegmentCount

private int macroSegmentCount

macroSegmentId

private int macroSegmentId

MACRO_LAST_SEGMENT

protected static final int MACRO_LAST_SEGMENT

MACRO_SEGMENT_COUNT

protected static final int MACRO_SEGMENT_COUNT

MACRO_SEGMENT_ID

protected static final int MACRO_SEGMENT_ID

MAX_DATA_CODEWORDS

protected static final int MAX_DATA_CODEWORDS

MIXED

protected static final int MIXED

MIXED_SET

private static final String MIXED_SET

ML

protected static final int ML

MOD

protected static final int MOD

NUMERIC_MODE

protected static final int NUMERIC_MODE

options

private int options
Holds value of property options.

outBits

private byte[] outBits
Holds value of property outBits.

PAL

protected static final int PAL

PDF417_AUTO_ERROR_LEVEL

public static final int PDF417_AUTO_ERROR_LEVEL
The error level correction is set automatically according to ISO 15438 recomendations.

PDF417_FIXED_COLUMNS

public static final int PDF417_FIXED_COLUMNS
The size will be at least codeColumns with a variable number of codeRows.

PDF417_FIXED_RECTANGLE

public static final int PDF417_FIXED_RECTANGLE
The size of the barcode will be at least codeColumns*codeRows.

PDF417_FIXED_ROWS

public static final int PDF417_FIXED_ROWS
The size will be at least codeRows with a variable number of codeColumns.

PDF417_FORCE_BINARY

public static final int PDF417_FORCE_BINARY
One single binary segment is used

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.

PDF417_USE_ASPECT_RATIO

public static final int PDF417_USE_ASPECT_RATIO
Auto-size is made based on aspectRatio and yHeight.

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.

PDF417_USE_MACRO

public static final int PDF417_USE_MACRO
Use Macro PDF417 Encoding

See Also: setMacroFileId BarcodePDF417 BarcodePDF417

PDF417_USE_RAW_CODEWORDS

public static final int PDF417_USE_RAW_CODEWORDS
No text interpretation is done and the content of codewords is used directly.

PL

protected static final int PL

PS

protected static final int PS

PUNCTUATION

protected static final int PUNCTUATION

PUNCTUATION_SET

private static final String PUNCTUATION_SET

segmentList

protected BarcodePDF417.SegmentList segmentList

SPACE

protected static final int SPACE

START_CODE_SIZE

protected static final int START_CODE_SIZE

START_PATTERN

protected static final int START_PATTERN

STOP_PATTERN

protected static final int STOP_PATTERN

STOP_SIZE

protected static final int STOP_SIZE

text

private byte[] text
Holds value of property text.

TEXT_MODE

protected static final int TEXT_MODE

yHeight

private float yHeight
Holds value of property yHeight.

Constructor Detail

BarcodePDF417

public BarcodePDF417()
Creates a new BarcodePDF417 with the default settings.

Method Detail

append

private void append(int in, int len)

append

private void append(String s)

assemble

protected void assemble()

basicNumberCompaction

protected void basicNumberCompaction(int start, int length)

basicNumberCompaction

private void basicNumberCompaction(byte[] input, int start, int length)

breakString

void breakString()

byteCompaction

void byteCompaction(int start, int length)

byteCompaction6

protected void byteCompaction6(int start)

calculateErrorCorrection

protected void calculateErrorCorrection(int dest)

checkSegmentType

protected boolean checkSegmentType(BarcodePDF417.Segment segment, char type)

createAwtImage

public Image createAwtImage(Color foreground, Color background)
Creates a java.awt.Image.

Parameters: foreground the color of the bars background the color of the background

Returns: the image

dumpList

protected void dumpList()

getAspectRatio

public float getAspectRatio()
Gets the barcode aspect ratio.

Returns: the barcode aspect ratio

getBitColumns

public int getBitColumns()
Gets the number of X pixels of outBits.

Returns: the number of X pixels of outBits

getCodeColumns

public int getCodeColumns()
Gets the number of barcode data columns.

Returns: he number of barcode data columns

getCodeRows

public int getCodeRows()
Gets the number of Y pixels of outBits. It is also the number of rows in the barcode.

Returns: the number of Y pixels of outBits

getCodewords

public int[] getCodewords()
Gets the codeword array. This array is always 928 elements long. It can be writen to if the option PDF417_USE_RAW_CODEWORDS is set.

Returns: the codeword array

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

getImage

public Image getImage()
Gets an Image with the barcode. The image will have to be scaled in the Y direction by yHeightfor the barcode to have the right printing aspect.

Returns: the barcode Image

Throws: BadElementException on error

getLenCodewords

public int getLenCodewords()
Gets the length of the codewords.

Returns: the length of the codewords

getMaxSquare

protected int getMaxSquare()

getOptions

public int getOptions()
Gets the options to generate the barcode.

Returns: the options to generate the barcode

getOutBits

public byte[] getOutBits()
Gets the raw image bits of the barcode. The image will have to be scaled in the Y direction by yHeight.

Returns: The raw barcode image

getSegmentLength

protected int getSegmentLength(BarcodePDF417.Segment segment)

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

getTextTypeAndValue

private static int getTextTypeAndValue(byte[] input, int maxLength, int idx)

getTextTypeAndValue

protected int getTextTypeAndValue(int maxLength, int idx)

getYHeight

public float getYHeight()
Gets the Y pixel height relative to X.

Returns: the Y pixel height relative to X

macroCodes

private void macroCodes()

maxPossibleErrorLevel

protected static int maxPossibleErrorLevel(int remain)

numberCompaction

private void numberCompaction(byte[] input, int start, int length)

numberCompaction

protected void numberCompaction(int start, int length)

outCodeword

protected void outCodeword(int codeword)

outCodeword17

protected void outCodeword17(int codeword)

outCodeword18

protected void outCodeword18(int codeword)

outPaintCode

protected void outPaintCode()

outStartPattern

protected void outStartPattern()

outStopPattern

protected void outStopPattern()

paintCode

public void paintCode()
Paints the barcode. If no exception was thrown a valid barcode is available.

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

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

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

setDefaultParameters

public void setDefaultParameters()
Set the default settings that correspond to PDF417_USE_ASPECT_RATIO and PDF417_AUTO_ERROR_LEVEL.

setErrorLevel

public void setErrorLevel(int errorLevel)
Sets the error level correction for the barcode.

Parameters: errorLevel the error level correction for the barcode

setLenCodewords

public void setLenCodewords(int lenCodewords)
Sets the length of the codewords.

Parameters: lenCodewords the length of the codewords

setMacroFileId

public void setMacroFileId(String id)
Sets the File ID for macro PDF417 encoding

Parameters: id the file id

setMacroSegmentCount

public void setMacroSegmentCount(int cnt)
Sets the segment count for macro PDF417 encoding

Parameters: cnt the number of macro segments

See Also: BarcodePDF417

setMacroSegmentId

public void setMacroSegmentId(int id)
Sets the segment id for macro PDF417 encoding

Parameters: id the id (starting at 0)

See Also: BarcodePDF417

setOptions

public void setOptions(int options)
Sets the options to generate the barcode. This can be all the PDF417_* constants.

Parameters: options the options to generate 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(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

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

textCompaction

private void textCompaction(byte[] input, int start, int length)

textCompaction

protected void textCompaction(int start, int length)