Class Barcode128


  • public class Barcode128
    extends Barcode1D
    BarCode 128 is a high-density linear barcode symbology defined in ISO/IEC 15417:2007. It is used for alphanumeric or numeric-only barcodes. It can encode all 128 characters of ASCII
    • Constructor Detail

      • Barcode128

        public Barcode128​(PdfDocument document,
                          PdfFont font)
        Creates new Barcode128, which will use the provided font
        Parameters:
        document - The document to which the barcode will be added
        font - The font to use
    • Method Detail

      • setCodeSet

        public void setCodeSet​(Barcode128.Barcode128CodeSet codeSet)
        Sets the code set to use.
        Parameters:
        codeSet - the code set to use.
      • removeFNC1

        public static java.lang.String removeFNC1​(java.lang.String code)
        Removes the FNC1 codes in the text.
        Parameters:
        code - The text to clean
        Returns:
        The cleaned text
      • getHumanReadableUCCEAN

        public static java.lang.String getHumanReadableUCCEAN​(java.lang.String code)
        Gets the human readable text of a sequence of AI.
        Parameters:
        code - the text
        Returns:
        the human readable text
      • getRawText

        public static java.lang.String getRawText​(java.lang.String text,
                                                  boolean ucc,
                                                  Barcode128.Barcode128CodeSet codeSet)
        Converts the human readable text to the characters needed to create a barcode using the specified code set.
        Parameters:
        text - the text to convert
        ucc - true if it is an UCC/EAN-128. In this case the character FNC1 is added
        codeSet - forced code set, or AUTO for optimized barcode.
        Returns:
        the code ready to be fed to getBarsCode128Raw()
      • getRawText

        public static java.lang.String getRawText​(java.lang.String text,
                                                  boolean ucc)
        Converts the human readable text to the characters needed to create a barcode. Some optimization is done to get the shortest code.
        Parameters:
        text - the text to convert
        ucc - true if it is an UCC/EAN-128. In this case the character FNC1 is added
        Returns:
        the code ready to be fed to getBarsCode128Raw()
      • getBarsCode128Raw

        public static byte[] getBarsCode128Raw​(java.lang.String text)
        Generates the bars. The input has the actual barcodes, not the human readable text.
        Parameters:
        text - the barcode
        Returns:
        the bars
      • 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 class Barcode1D
        Returns:
        the size the barcode occupies.
      • placeBarcode

        public Rectangle placeBarcode​(PdfCanvas canvas,
                                      Color barColor,
                                      Color textColor)
        Places the barcode in a PdfCanvas. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.

        The bars and text are written in the following colors:

        barColor textColor Result
        null null bars and text painted with current fill color
        barColor null bars and text painted with barColor
        null textColor bars painted with current color
        text painted with textColor
        barColor textColor bars painted with barColor
        text painted with textColor
        Specified by:
        placeBarcode in class Barcode1D
        Parameters:
        canvas - the PdfCanvas where the barcode will be placed
        barColor - the color of the bars. It can be null
        textColor - the color of the text. It can be null
        Returns:
        the dimensions the barcode occupies
      • setCode

        public void setCode​(java.lang.String code)
        Sets the code to generate. If it's an UCC code and starts with '(' it will be split by the AI. This code in UCC mode is valid:
        (01)00000090311314(10)ABC123(15)060916
        Overrides:
        setCode in class Barcode1D
        Parameters:
        code - the code to generate
      • createAwtImage

        public java.awt.Image createAwtImage​(java.awt.Color foreground,
                                             java.awt.Color background)
        Creates a java.awt.Image. This image only contains the bars without any text.
        Specified by:
        createAwtImage in class Barcode1D
        Parameters:
        foreground - the color of the bars
        background - the color of the background
        Returns:
        the image
      • isNextDigits

        static boolean isNextDigits​(java.lang.String text,
                                    int textIndex,
                                    int numDigits)
        Returns true if the next numDigits starting from index textIndex are numeric skipping any FNC1.
        Parameters:
        text - the text to check
        textIndex - where to check from
        numDigits - the number of digits to check
        Returns:
        the check result
      • getPackedRawDigits

        static java.lang.String getPackedRawDigits​(java.lang.String text,
                                                   int textIndex,
                                                   int numDigits)
        Packs the digits for charset C also considering FNC1. It assumes that all the parameters are valid.
        Parameters:
        text - the text to pack
        textIndex - where to pack from
        numDigits - the number of digits to pack. It is always an even number
        Returns:
        the packed digits, two digits per character