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.
    • Field Detail

      • PDF417_USE_ASPECT_RATIO

        public static final int PDF417_USE_ASPECT_RATIO
        Auto-size is made based on aspectRatio and yHeight.
        See Also:
        Constant Field Values
      • PDF417_FIXED_RECTANGLE

        public static final int PDF417_FIXED_RECTANGLE
        The size of the barcode will be at least codeColumns*codeRows.
        See Also:
        Constant Field Values
      • PDF417_FIXED_COLUMNS

        public static final int PDF417_FIXED_COLUMNS
        The size will be at least codeColumns with a variable number of codeRows.
        See Also:
        Constant Field Values
      • PDF417_FIXED_ROWS

        public static final int PDF417_FIXED_ROWS
        The size will be at least codeRows with a variable number of codeColumns.
        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
        No text interpretation is done and the content of codewords 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
      • macroSegmentCount

        private int macroSegmentCount
      • macroSegmentId

        private int macroSegmentId
      • macroFileId

        private java.lang.String macroFileId
      • macroIndex

        private int macroIndex
      • bitPtr

        protected int bitPtr
      • cwPtr

        protected int cwPtr
      • ABSOLUTE_MAX_TEXT_SIZE

        protected static final int ABSOLUTE_MAX_TEXT_SIZE
        See Also:
        Constant Field Values
      • CLUSTERS

        private static final int[][] CLUSTERS
      • ERROR_LEVEL

        private static final int[][] ERROR_LEVEL
      • 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.
      • text

        private byte[] text
        Holds value of property text.
      • 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.
    • Constructor Detail

      • BarcodePDF417

        public BarcodePDF417()
        Creates a new BarcodePDF417 with the default settings.
    • 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 to PDF417_USE_ASPECT_RATIO and PDF417_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

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

        protected int getTextTypeAndValue​(int maxLength,
                                          int idx)
      • textCompaction

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

        protected void textCompaction​(int start,
                                      int length)
      • basicNumberCompaction

        protected void basicNumberCompaction​(int start,
                                             int length)
      • basicNumberCompaction

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

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

        protected void numberCompaction​(int start,
                                        int length)
      • byteCompaction6

        protected void byteCompaction6​(int start)
      • byteCompaction

        void byteCompaction​(int start,
                            int length)
      • breakString

        void breakString()
      • assemble

        protected void assemble()
      • macroCodes

        private void macroCodes()
      • append

        private void append​(int in,
                            int len)
      • append

        private void append​(java.lang.String s)
      • 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 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
      • 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
      • getBitColumns

        public int getBitColumns()
        Gets the number of X pixels of outBits.
        Returns:
        the number of X pixels of outBits
      • 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
      • 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 option PDF417_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
      • 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 the PDF417_* 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
      • placeBarcode

        public void placeBarcode​(PdfContentByte cb,
                                 BaseColor foreground,
                                 float moduleHeight,
                                 float moduleWidth)
      • getBarcodeSize

        public Rectangle getBarcodeSize()
        Gets the size of the barcode grid.
      • createAwtImage

        public java.awt.Image createAwtImage​(java.awt.Color foreground,
                                             java.awt.Color background)
        Creates a java.awt.Image.
        Parameters:
        foreground - the color of the bars
        background - the color of the background
        Returns:
        the image