Class BarcodeDatamatrix
- java.lang.Object
-
- com.itextpdf.text.pdf.BarcodeDatamatrix
-
public class BarcodeDatamatrix extends java.lang.Object
A DataMatrix 2D barcode generator.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BarcodeDatamatrix.DmParams
(package private) static class
BarcodeDatamatrix.Placement
(package private) static class
BarcodeDatamatrix.ReedSolomon
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_DATA_MATRIX_ENCODING
static int
DM_ASCII
ASCII encodation.static int
DM_AUTO
The best encodation will be used.static int
DM_B256
Binary encodation.static int
DM_C40
C40 encodation.static int
DM_EDIFACT
EDIFACT encodation.static int
DM_ERROR_EXTENSION
An error while parsing an extension.static int
DM_ERROR_INVALID_SQUARE
The dimensions given for the symbol are illegal.static int
DM_ERROR_TEXT_TOO_BIG
The text is too big for the symbology capabilities.static int
DM_EXTENSION
Allows extensions to be embedded at the start of the text.static int
DM_NO_ERROR
No error.static int
DM_RAW
No encodation needed.static int
DM_TEST
Doesn't generate the image but returns all the other information.static int
DM_TEXT
TEXT encodation.static int
DM_X12
X12 encodation.static int
DM_X21
Deprecated.UseBarcodeDataMatrix#DM_X12
instead.private static BarcodeDatamatrix.DmParams[]
dmSizes
private java.lang.String
encoding
private static byte
EXTENDED_ASCII
private int
extOut
private static int[][]
f
private boolean
forceSquareSize
private int
height
private byte[]
image
private static byte
LATCH_B256
private static byte
LATCH_C40
private static byte
LATCH_EDIFACT
private static byte
LATCH_TEXT
private static byte
LATCH_X12
private int
options
private static byte
PADDING
private short[]
place
private static int[][]
switchMode
private static byte
UNLATCH
private int
width
private int
ws
private static java.lang.String
X12
-
Constructor Summary
Constructors Constructor Description BarcodeDatamatrix()
Creates an instance of this class.BarcodeDatamatrix(java.lang.String code)
BarcodeDatamatrix(java.lang.String code, java.lang.String encoding)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
asciiEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)
private static int
b256Encodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)
private static int
C40OrTextEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, boolean c40, int symbolIndex, int prevEnc, int origDataOffset)
java.awt.Image
createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
.Image
createImage()
Gets anImage
with the barcode.private void
draw(byte[] data, int dataSize, BarcodeDatamatrix.DmParams dm)
private static int
EdifactEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset, boolean sizeFixed)
int
generate(byte[] text, int textOffset, int textSize)
Creates a barcode.int
generate(java.lang.String text)
Creates a barcode.private static int
getEncodation(byte[] text, int textOffset, int textSize, byte[] data, int dataOffset, int dataSize, int options, boolean sizeFixed)
int
getHeight()
Gets the height of the barcode.byte[]
getImage()
Gets the generated image.private static int
getNumber(byte[] text, int ptrIn, int n)
int
getOptions()
Gets the barcode options.int
getWidth()
Gets the width of the barcode.int
getWs()
Gets the whitespace border around the barcode.private static boolean
isDigit(int c)
private static void
makePadding(byte[] data, int position, int count)
private static int
minValueInColumn(int[][] array, int column)
void
placeBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth)
private int
processExtensions(byte[] text, int textOffset, int textSize, byte[] data)
private static void
randomizationAlgorithm255(byte[] data, int j)
private void
setBit(int x, int y, int xByte)
void
setForceSquareSize(boolean forceSquareSize)
void
setHeight(int height)
Sets the height of the barcode.void
setOptions(int options)
Sets the options for the barcode generation.void
setWidth(int width)
Sets the width of the barcode.void
setWs(int ws)
Sets the whitespace border around the barcode.private static void
solveFAndSwitchMode(int[] forMin, int mode, int currIndex)
private static int
valuePositionInColumn(int[][] array, int column, int value)
private static int
X12Encodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)
-
-
-
Field Detail
-
DM_NO_ERROR
public static final int DM_NO_ERROR
No error.- See Also:
- Constant Field Values
-
DM_ERROR_TEXT_TOO_BIG
public static final int DM_ERROR_TEXT_TOO_BIG
The text is too big for the symbology capabilities.- See Also:
- Constant Field Values
-
DM_ERROR_INVALID_SQUARE
public static final int DM_ERROR_INVALID_SQUARE
The dimensions given for the symbol are illegal.- See Also:
- Constant Field Values
-
DM_ERROR_EXTENSION
public static final int DM_ERROR_EXTENSION
An error while parsing an extension.- See Also:
- Constant Field Values
-
DM_AUTO
public static final int DM_AUTO
The best encodation will be used.- See Also:
- Constant Field Values
-
DM_ASCII
public static final int DM_ASCII
ASCII encodation.- See Also:
- Constant Field Values
-
DM_C40
public static final int DM_C40
C40 encodation.- See Also:
- Constant Field Values
-
DM_TEXT
public static final int DM_TEXT
TEXT encodation.- See Also:
- Constant Field Values
-
DM_B256
public static final int DM_B256
Binary encodation.- See Also:
- Constant Field Values
-
DM_X12
public static final int DM_X12
X12 encodation.- See Also:
- Constant Field Values
-
DM_X21
@Deprecated public static final int DM_X21
Deprecated.UseBarcodeDataMatrix#DM_X12
instead.X12 encodation.- See Also:
- Constant Field Values
-
DM_EDIFACT
public static final int DM_EDIFACT
EDIFACT encodation.- See Also:
- Constant Field Values
-
DM_RAW
public static final int DM_RAW
No encodation needed. The bytes provided are already encoded.- See Also:
- Constant Field Values
-
DM_EXTENSION
public static final int DM_EXTENSION
Allows extensions to be embedded at the start of the text.- See Also:
- Constant Field Values
-
DM_TEST
public static final int DM_TEST
Doesn't generate the image but returns all the other information.- See Also:
- Constant Field Values
-
DEFAULT_DATA_MATRIX_ENCODING
public static final java.lang.String DEFAULT_DATA_MATRIX_ENCODING
- See Also:
- Constant Field Values
-
LATCH_B256
private static final byte LATCH_B256
- See Also:
- Constant Field Values
-
LATCH_EDIFACT
private static final byte LATCH_EDIFACT
- See Also:
- Constant Field Values
-
LATCH_X12
private static final byte LATCH_X12
- See Also:
- Constant Field Values
-
LATCH_TEXT
private static final byte LATCH_TEXT
- See Also:
- Constant Field Values
-
LATCH_C40
private static final byte LATCH_C40
- See Also:
- Constant Field Values
-
UNLATCH
private static final byte UNLATCH
- See Also:
- Constant Field Values
-
EXTENDED_ASCII
private static final byte EXTENDED_ASCII
- See Also:
- Constant Field Values
-
PADDING
private static final byte PADDING
- See Also:
- Constant Field Values
-
encoding
private java.lang.String encoding
-
dmSizes
private static final BarcodeDatamatrix.DmParams[] dmSizes
-
X12
private static final java.lang.String X12
- See Also:
- Constant Field Values
-
extOut
private int extOut
-
place
private short[] place
-
image
private byte[] image
-
height
private int height
-
width
private int width
-
ws
private int ws
-
options
private int options
-
f
private static int[][] f
-
switchMode
private static int[][] switchMode
-
forceSquareSize
private boolean forceSquareSize
-
-
Constructor Detail
-
BarcodeDatamatrix
public BarcodeDatamatrix()
Creates an instance of this class.
-
BarcodeDatamatrix
public BarcodeDatamatrix(java.lang.String code) throws java.io.UnsupportedEncodingException
- Throws:
java.io.UnsupportedEncodingException
-
BarcodeDatamatrix
public BarcodeDatamatrix(java.lang.String code, java.lang.String encoding) throws java.io.UnsupportedEncodingException
- Throws:
java.io.UnsupportedEncodingException
-
-
Method Detail
-
setBit
private void setBit(int x, int y, int xByte)
-
draw
private void draw(byte[] data, int dataSize, BarcodeDatamatrix.DmParams dm)
-
makePadding
private static void makePadding(byte[] data, int position, int count)
-
isDigit
private static boolean isDigit(int c)
-
asciiEncodation
private static int asciiEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)
-
b256Encodation
private static int b256Encodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)
-
randomizationAlgorithm255
private static void randomizationAlgorithm255(byte[] data, int j)
-
X12Encodation
private static int X12Encodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset)
-
EdifactEncodation
private static int EdifactEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, int symbolIndex, int prevEnc, int origDataOffset, boolean sizeFixed)
-
C40OrTextEncodation
private static int C40OrTextEncodation(byte[] text, int textOffset, int textLength, byte[] data, int dataOffset, int dataLength, boolean c40, int symbolIndex, int prevEnc, int origDataOffset)
-
minValueInColumn
private static int minValueInColumn(int[][] array, int column)
-
valuePositionInColumn
private static int valuePositionInColumn(int[][] array, int column, int value)
-
solveFAndSwitchMode
private static void solveFAndSwitchMode(int[] forMin, int mode, int currIndex)
-
getEncodation
private static int getEncodation(byte[] text, int textOffset, int textSize, byte[] data, int dataOffset, int dataSize, int options, boolean sizeFixed)
-
getNumber
private static int getNumber(byte[] text, int ptrIn, int n)
-
processExtensions
private int processExtensions(byte[] text, int textOffset, int textSize, byte[] data)
-
generate
public int generate(java.lang.String text) throws java.io.UnsupportedEncodingException
Creates a barcode. TheString
is interpreted with the ISO-8859-1 encoding- Parameters:
text
- the text- Returns:
- the status of the generation. It can be one of this values:
DM_NO_ERROR
- no error.
DM_ERROR_TEXT_TOO_BIG
- the text is too big for the symbology capabilities.
DM_ERROR_INVALID_SQUARE
- the dimensions given for the symbol are illegal.
DM_ERROR_EXTENSION
- an error was while parsing an extension. - Throws:
java.io.UnsupportedEncodingException
- on error
-
generate
public int generate(byte[] text, int textOffset, int textSize)
Creates a barcode.- Parameters:
text
- the texttextOffset
- the offset to the start of the texttextSize
- the text size- Returns:
- the status of the generation. It can be one of this values:
DM_NO_ERROR
- no error.
DM_ERROR_TEXT_TOO_BIG
- the text is too big for the symbology capabilities.
DM_ERROR_INVALID_SQUARE
- the dimensions given for the symbol are illegal.
DM_ERROR_EXTENSION
- an error was while parsing an extension.
-
createImage
public Image createImage() throws BadElementException
Gets anImage
with the barcode. A successful call to the methodgenerate()
before calling this method is required.- Returns:
- the barcode
Image
- Throws:
BadElementException
- on error
-
getImage
public byte[] getImage()
Gets the generated image. The image is represented as a stream of bytes, each byte representing 8 pixels, 0 for white and 1 for black, with the high-order bit of each byte first. Each row is aligned at byte boundaries. The dimensions of the image are defined by height and width plus 2 * ws.- Returns:
- the generated image
-
getHeight
public int getHeight()
Gets the height of the barcode. Will contain the real height used after a successful call togenerate()
. This height doesn't include the whitespace border, if any.- Returns:
- the height of the barcode
-
setHeight
public void setHeight(int height)
Sets the height of the barcode. If the height is zero it will be calculated. This height doesn't include the whitespace border, if any.The allowed dimensions are (height, width):
10, 10
12, 12
8, 18
14, 14
8, 32
16, 16
12, 26
18, 18
20, 20
12, 36
22, 22
16, 36
24, 24
26, 26
16, 48
32, 32
36, 36
40, 40
44, 44
48, 48
52, 52
64, 64
72, 72
80, 80
88, 88
96, 96
104, 104
120, 120
132, 132
144, 144- Parameters:
height
- the height of the barcode
-
getWidth
public int getWidth()
Gets the width of the barcode. Will contain the real width used after a successful call togenerate()
. This width doesn't include the whitespace border, if any.- Returns:
- the width of the barcode
-
setWidth
public void setWidth(int width)
Sets the width of the barcode. If the width is zero it will be calculated. This width doesn't include the whitespace border, if any.The allowed dimensions are (height, width):
10, 10
12, 12
8, 18
14, 14
8, 32
16, 16
12, 26
18, 18
20, 20
12, 36
22, 22
16, 36
24, 24
26, 26
16, 48
32, 32
36, 36
40, 40
44, 44
48, 48
52, 52
64, 64
72, 72
80, 80
88, 88
96, 96
104, 104
120, 120
132, 132
144, 144- Parameters:
width
- the width of the barcode
-
getWs
public int getWs()
Gets the whitespace border around the barcode.- Returns:
- the whitespace border around the barcode
-
setWs
public void setWs(int ws)
Sets the whitespace border around the barcode.- Parameters:
ws
- the whitespace border around the barcode
-
getOptions
public int getOptions()
Gets the barcode options.- Returns:
- the barcode options
-
setOptions
public void setOptions(int options)
Sets the options for the barcode generation. The options can be:One of:
DM_AUTO
- the best encodation will be used
DM_ASCII
- ASCII encodation
DM_C40
- C40 encodation
DM_TEXT
- TEXT encodation
DM_B256
- binary encodation
DM_X21
- X21 encodation
DM_EDIFACT
- EDIFACT encodation
DM_RAW
- no encodation. The bytes provided are already encoded and will be added directly to the barcode, using padding if needed. It assumes that the encodation state is left at ASCII after the last byte.
One of:
DM_EXTENSION
- allows extensions to be embedded at the start of the text:exxxxxx - ECI number xxxxxx
m5 - macro 5
m6 - macro 6
f - FNC1
saabbccccc - Structured Append, aa symbol position (1-16), bb total number of symbols (2-16), ccccc file identification (0-64515)
p - Reader programming
. - extension terminatorExample for a structured append, symbol 2 of 6, with FNC1 and ECI 000005. The actual text is "Hello".
s020600075fe000005.Hello
One of:
DM_TEST
- doesn't generate the image but returns all the other information.- Parameters:
options
- the barcode options
-
setForceSquareSize
public void setForceSquareSize(boolean forceSquareSize)
-
placeBarcode
public void placeBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth)
-
createAwtImage
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
. A successful call to the methodgenerate()
before calling this method is required.- Parameters:
foreground
- the color of the barsbackground
- the color of the background- Returns:
- the image
-
-