com.lowagie.text.pdf

Class BarcodePDF417


public class BarcodePDF417
extends java.lang.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 class
BarcodePDF417.Segment
protected static class
BarcodePDF417.SegmentList

Field Summary

protected static int
ABSOLUTE_MAX_TEXT_SIZE
protected static int
AL
protected static int
ALPHA
protected static int
AS
protected static int
BYTESHIFT
protected static int
BYTE_MODE
protected static int
BYTE_MODE_6
(package private) static int[][]
CLUSTERS
(package private) static int[][]
ERROR_LEVEL
protected static int
ISBYTE
protected static int
LL
protected static int
LOWER
protected static int
MAX_DATA_CODEWORDS
protected static int
MIXED
(package private) static String
MIXED_SET
protected static int
ML
protected static int
MOD
protected static int
NUMERIC_MODE
protected static int
PAL
static int
PDF417_AUTO_ERROR_LEVEL
The error level correction is set automatically according to ISO 15438 recomendations.
static int
PDF417_FIXED_COLUMNS
The size will be at least codeColumns with a variable number of codeRows.
static int
PDF417_FIXED_RECTANGLE
The size of the barcode will be at least codeColumns*codeRows.
static int
PDF417_FIXED_ROWS
The size will be at least codeRows with a variable number of codeColumns.
static 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 on aspectRatio and yHeight.
static int
PDF417_USE_ERROR_LEVEL
The error level correction is set by the user.
static int
PDF417_USE_RAW_CODEWORDS
No text interpretation is done and the content of codewords is used directly.
protected static int
PL
protected static int
PS
protected static int
PUNCTUATION
(package private) static String
PUNCTUATION_SET
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
aspectRatio
Holds value of property aspectRatio.
private int
bitColumns
Holds value of property bitColumns.
protected int
bitPtr
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
private int
errorLevel
Holds value of property errorLevel.
private int
lenCodewords
Holds value of property lenCodewords.
private int
options
Holds value of property options.
private byte[]
outBits
Holds value of property outBits.
protected BarcodePDF417.SegmentList
segmentList
private byte[]
text
Holds value of property text.
private float
yHeight
Holds value of property yHeight.

Constructor Summary

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

Method Summary

protected void
assemble()
protected void
basicNumberCompaction(int start, int length)
(package private) void
breakString()
(package private) void
byteCompaction(int start, int length)
protected void
byteCompaction6(int start)
protected void
calculateErrorCorrection(int dest)
protected boolean
checkSegmentType(BarcodePDF417.Segment segment, char type)
java.awt.Image
createAwtImage(Color foreground, Color background)
Creates a java.awt.Image.
protected void
dumpList()
float
getAspectRatio()
Gets the barcode aspect ratio.
int
getBitColumns()
Gets the number of X pixels of outBits.
int
getCodeColumns()
Gets the number of barcode data columns.
int
getCodeRows()
Gets the number of Y pixels of outBits.
int[]
getCodewords()
Gets the codeword array.
int
getErrorLevel()
Gets the error level correction used for the barcode.
Image
getImage()
Gets an Image with the barcode.
int
getLenCodewords()
Gets the length of the codewords.
protected int
getMaxSquare()
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)
byte[]
getText()
Gets the bytes that form the barcode.
protected int
getTextTypeAndValue(int maxLength, int idx)
float
getYHeight()
Gets the Y pixel height relative to X.
protected static int
maxPossibleErrorLevel(int remain)
protected void
numberCompaction(int start, int length)
protected void
outCodeword(int codeword)
protected void
outCodeword17(int codeword)
protected void
outCodeword18(int codeword)
protected void
outPaintCode()
protected void
outStartPattern()
protected void
outStopPattern()
void
paintCode()
Paints the barcode.
void
setAspectRatio(float aspectRatio)
Sets the barcode aspect ratio.
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 to PDF417_USE_ASPECT_RATIO and PDF417_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
setOptions(int options)
Sets the options to generate the barcode.
void
setText(String s)
Sets the text that will form the barcode.
void
setText(byte[] text)
Sets the bytes that form the barcode.
void
setYHeight(float yHeight)
Sets the Y pixel height relative to X.
protected void
textCompaction(int start, int length)

Field Details

ABSOLUTE_MAX_TEXT_SIZE

protected static final int ABSOLUTE_MAX_TEXT_SIZE
Field Value:
5420

AL

protected static final int AL
Field Value:
28

ALPHA

protected static final int ALPHA
Field Value:
65536

AS

protected static final int AS
Field Value:
27

BYTESHIFT

protected static final int BYTESHIFT
Field Value:
913

BYTE_MODE

protected static final int BYTE_MODE
Field Value:
901

BYTE_MODE_6

protected static final int BYTE_MODE_6
Field Value:
924

CLUSTERS

(package private) static int[][] CLUSTERS

ERROR_LEVEL

(package private) static int[][] ERROR_LEVEL

ISBYTE

protected static final int ISBYTE
Field Value:
1048576

LL

protected static final int LL
Field Value:
27

LOWER

protected static final int LOWER
Field Value:
131072

MAX_DATA_CODEWORDS

protected static final int MAX_DATA_CODEWORDS
Field Value:
926

MIXED

protected static final int MIXED
Field Value:
262144

MIXED_SET

(package private) static String MIXED_SET

ML

protected static final int ML
Field Value:
28

MOD

protected static final int MOD
Field Value:
929

NUMERIC_MODE

protected static final int NUMERIC_MODE
Field Value:
902

PAL

protected static final int PAL
Field Value:
29

PDF417_AUTO_ERROR_LEVEL

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

PDF417_FIXED_COLUMNS

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

PDF417_FIXED_RECTANGLE

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

PDF417_FIXED_ROWS

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

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.
Field Value:
128

PDF417_USE_ASPECT_RATIO

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

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.
Field Value:
16

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.
Field Value:
64

PL

protected static final int PL
Field Value:
25

PS

protected static final int PS
Field Value:
29

PUNCTUATION

protected static final int PUNCTUATION
Field Value:
524288

PUNCTUATION_SET

(package private) static String PUNCTUATION_SET

SPACE

protected static final int SPACE
Field Value:
26

START_CODE_SIZE

protected static final int START_CODE_SIZE
Field Value:
17

START_PATTERN

protected static final int START_PATTERN
Field Value:
130728

STOP_PATTERN

protected static final int STOP_PATTERN
Field Value:
260649

STOP_SIZE

protected static final int STOP_SIZE
Field Value:
18

TEXT_MODE

protected static final int TEXT_MODE
Field Value:
900

aspectRatio

private float aspectRatio
Holds value of property aspectRatio.

bitColumns

private int bitColumns
Holds value of property bitColumns.

bitPtr

protected int bitPtr

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

errorLevel

private int errorLevel
Holds value of property errorLevel.

lenCodewords

private int lenCodewords
Holds value of property lenCodewords.

options

private int options
Holds value of property options.

outBits

private byte[] outBits
Holds value of property outBits.

segmentList

protected BarcodePDF417.SegmentList segmentList

text

private byte[] text
Holds value of property text.

yHeight

private float yHeight
Holds value of property yHeight.

Constructor Details

BarcodePDF417

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

Method Details

assemble

protected void assemble()

basicNumberCompaction

protected void basicNumberCompaction(int start,
                                     int length)

breakString

(package private)  void breakString()

byteCompaction

(package private)  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 java.awt.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()
            throws BadElementException
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

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

maxPossibleErrorLevel

protected static int maxPossibleErrorLevel(int remain)

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

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(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

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

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

protected void textCompaction(int start,
                              int length)