Class BarcodeEAN


  • public class BarcodeEAN
    extends Barcode
    Generates barcodes in several formats: EAN13, EAN8, UPCA, UPCE, supplemental 2 and 5. The default parameters are:
    x = 0.8f;
    font = BaseFont.createFont("Helvetica", "winansi", false);
    size = 8;
    baseline = size;
    barHeight = size * 3;
    guardBars = true;
    codeType = EAN13;
    code = "";
     
    • Field Detail

      • GUARD_EMPTY

        private static final int[] GUARD_EMPTY
        The bar positions that are guard bars.
      • GUARD_UPCA

        private static final int[] GUARD_UPCA
        The bar positions that are guard bars.
      • GUARD_EAN13

        private static final int[] GUARD_EAN13
        The bar positions that are guard bars.
      • GUARD_EAN8

        private static final int[] GUARD_EAN8
        The bar positions that are guard bars.
      • GUARD_UPCE

        private static final int[] GUARD_UPCE
        The bar positions that are guard bars.
      • TEXTPOS_EAN13

        private static final float[] TEXTPOS_EAN13
        The x coordinates to place the text.
      • TEXTPOS_EAN8

        private static final float[] TEXTPOS_EAN8
        The x coordinates to place the text.
      • BARS

        private static final byte[][] BARS
        The basic bar widths.
      • TOTALBARS_EAN13

        private static final int TOTALBARS_EAN13
        The total number of bars for EAN13.
        See Also:
        Constant Field Values
      • TOTALBARS_EAN8

        private static final int TOTALBARS_EAN8
        The total number of bars for EAN8.
        See Also:
        Constant Field Values
      • TOTALBARS_UPCE

        private static final int TOTALBARS_UPCE
        The total number of bars for UPCE.
        See Also:
        Constant Field Values
      • TOTALBARS_SUPP2

        private static final int TOTALBARS_SUPP2
        The total number of bars for supplemental 2.
        See Also:
        Constant Field Values
      • TOTALBARS_SUPP5

        private static final int TOTALBARS_SUPP5
        The total number of bars for supplemental 5.
        See Also:
        Constant Field Values
      • PARITY13

        private static final byte[][] PARITY13
        Sequence of parities to be used with EAN13.
      • PARITY2

        private static final byte[][] PARITY2
        Sequence of parities to be used with supplemental 2.
      • PARITY5

        private static final byte[][] PARITY5
        Sequence of parities to be used with supplemental 2.
      • PARITYE

        private static final byte[][] PARITYE
        Sequence of parities to be used with UPCE.
    • Constructor Detail

      • BarcodeEAN

        public BarcodeEAN()
        Creates new BarcodeEAN
    • Method Detail

      • calculateEANParity

        public static int calculateEANParity​(java.lang.String code)
        Calculates the EAN parity character.
        Parameters:
        code - the code
        Returns:
        the parity character
      • convertUPCAtoUPCE

        public static java.lang.String convertUPCAtoUPCE​(java.lang.String text)
        Converts an UPCA code into an UPCE code. If the code can not be converted a null is returned.
        Parameters:
        text - the code to convert. It must have 12 numeric characters
        Returns:
        the 8 converted digits or null if the code could not be converted
      • getBarsEAN13

        public static byte[] getBarsEAN13​(java.lang.String _code)
        Creates the bars for the barcode EAN13 and UPCA.
        Parameters:
        _code - the text with 13 digits
        Returns:
        the barcode
      • getBarsEAN8

        public static byte[] getBarsEAN8​(java.lang.String _code)
        Creates the bars for the barcode EAN8.
        Parameters:
        _code - the text with 8 digits
        Returns:
        the barcode
      • getBarsUPCE

        public static byte[] getBarsUPCE​(java.lang.String _code)
        Creates the bars for the barcode UPCE.
        Parameters:
        _code - the text with 8 digits
        Returns:
        the barcode
      • getBarsSupplemental2

        public static byte[] getBarsSupplemental2​(java.lang.String _code)
        Creates the bars for the barcode supplemental 2.
        Parameters:
        _code - the text with 2 digits
        Returns:
        the barcode
      • getBarsSupplemental5

        public static byte[] getBarsSupplemental5​(java.lang.String _code)
        Creates the bars for the barcode supplemental 5.
        Parameters:
        _code - the text with 5 digits
        Returns:
        the barcode
      • 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 Barcode
        Returns:
        the size the barcode occupies.
      • placeBarcode

        public Rectangle placeBarcode​(PdfContentByte cb,
                                      BaseColor barColor,
                                      BaseColor textColor)
        Places the barcode in a PdfContentByte. 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 Barcode
        Parameters:
        cb - the PdfContentByte 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
      • 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 Barcode
        Parameters:
        foreground - the color of the bars
        background - the color of the background
        Returns:
        the image