Class BarCode


  • public class BarCode
    extends java.lang.Object
    This class allows the creation of various bar code symbols. Simply call the appropriate method to create your BarCode then draw the result of getCanvas() onto a page:
     BarCode code = BarCode.newCode128("Code 128 Test");
     PDFCanvas canvas = code.getCanvas();
     page.drawCanvas(canvas, x, y, x+canvas.getWidth(), y+canvas.getHeight());
     
    Since:
    2.10 - although this class first appeared in 2.0, it was redesigned in 2.10
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char CODE128_SETA
      A character than can be used to force the Code 128 barcode to set A
      static char CODE128_SETB
      A character than can be used to force the Code 128 barcode to set B
      static char CODE128_SETC
      A character than can be used to force the Code 128 barcode to set C
      static char DATAMATRIX_LATCH_ANSIX12
      Represents the DataMatrix "Latch to ANSI X.12" character.
      static char DATAMATRIX_LATCH_ASCII
      Represents the DataMatrix "Latch to ASCII" character.
      static char DATAMATRIX_LATCH_BASE256
      Represents the DataMatrix "Latch to Base256" character.
      static char DATAMATRIX_LATCH_C40
      Represents the DataMatrix "Latch to C40" character.
      static char DATAMATRIX_LATCH_EDIFACT
      Represents the DataMatrix "Latch to EDIFACT" character.
      static char DATAMATRIX_LATCH_TEXT
      Represents the DataMatrix "Latch to Text" character.
      static char FNC1
      Represents the FNC1 character, used in a number of barcodes
      static char FNC2
      Represents the FNC1 character, used in a number of barcodes
      static char FNC3
      Represents the FNC1 character, used in a number of barcodes
      static char FNC4
      Represents the FNC1 character, used in a number of barcodes
      static char MAXICODE_GS
      Represents the MaxiCode "Group Seperator" characters (U+001D).
      static char MAXICODE_LATCHA
      Represents the MaxiCode "LATCH-A" control character.
      static char MAXICODE_LATCHB
      Represents the MaxiCode "LATCH-B" control character.
      static char MAXICODE_LOCK
      Represents the MaxiCode "LOCK-A", "LOCK-B" and "LOCK-C" control characters
      static char MAXICODE_RS
      Represents the MaxiCode "Record Seperator" characters (U+001E).
      static char MAXICODE_SHIFTA
      Represents the MaxiCode "SHIFT-A" control character.
      static char MAXICODE_SHIFTB
      Represents the MaxiCode "SHIFT-B" control character.
      static char MAXICODE_SHIFTC
      Represents the MaxiCode "SHIFT-C" control character.
      static char MAXICODE_SHIFTD
      Represents the MaxiCode "SHIFT-D" control character.
      static char MAXICODE_SHIFTE
      Represents the MaxiCode "SHIFT-E" control character.
      static char MAXICODE_THREESHIFTA
      Represents the MaxiCode "3 SHIFT-A" control character.
      static char MAXICODE_TWOSHIFTA
      Represents the MaxiCode "2 SHIFT-A" control character.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.image.BufferedImage getBufferedImage​(double scale, java.awt.Paint background)
      Create the BarCode as a BufferedImage.
      PDFCanvas getCanvas()
      Return a new PDFCanvas containing the barcode.
      java.awt.geom.Rectangle2D getContentRectangle()
      Return the location of the actual barcode in the Canvas, excluding any quiet-zone or text.
      float getHeight()
      Return the height of the symbol.
      float getMinimumHeight()
      Return the recommended minimum height for this symbol.
      java.lang.String getText()
      Return the value of the text content that will be shown below the BarCode.
      float getWidth()
      Return the width of the symbol.
      static BarCode newAusPost4S​(java.lang.String value)
      Create a new Australia Post 4-state Barcode.
      static BarCode newAztecCode​(java.lang.String data)
      Create a new Aztec code representing the specified String.
      static BarCode newCodabar​(java.lang.String value, float xunit)
      Create a new Codabar BarCode.
      static BarCode newCode128​(java.lang.String value)
      Create a new Code-128 BarCode with an X-unit of 1pt (0.353mm)
      static BarCode newCode128​(java.lang.String value, double xunit)
      Create a new Code-128 BarCode.
      static BarCode newCode39​(java.lang.String value, boolean checksum)
      Create a new Code 3 of 9 code with an X-unit of 1 and a thick/thin bar ratio of 2.8.
      static BarCode newCode39​(java.lang.String value, boolean checksum, float xunit, float ratio)
      Create a new Code 3 of 9 code.
      static BarCode newCode39Extended​(java.lang.String value, boolean checksum)
      Create a new Extended Code 3 of 9 ("Code 39+") code with an X-unit of 1pt (0.353mm) and a thick/thin bar ratio of 2.8 This algorithm uses the same symbology as Code 3 of 9 but can display all ASCII characters.
      static BarCode newCode39Extended​(java.lang.String value, boolean checksum, float xunit, float ratio)
      Create a new Extended Code 3 of 9 ("Code 39+") code.
      static BarCode newCode93​(java.lang.String value, float xunit)
      Create a new Code 93 code.
      static BarCode newDatabar​(boolean linkage, java.lang.String value, boolean truncated, boolean stacked)
      Create a new GS1 Databar (formerly known as RSS-14) barcode.
      static BarCode newDataMatrixCode​(byte[] data, int rows, int cols)
      Create a new Data Matrix code representing binary data.
      static BarCode newDataMatrixCode​(java.lang.String data)
      Create a new Data Matrix code.
      static BarCode newDataMatrixCode​(java.lang.String data, int rows, int cols)
      Create a new Data Matrix code of the specified dimensions.
      static BarCode newDataMatrixCode​(java.lang.String data, int rows, int cols, char encoder)
      Create a new Data Matrix code using the specified dimensions and encoder.
      static BarCode newDeutschePostCode​(java.lang.String value)
      Create a new DeutschePost Interleaved 2 of 5 code.
      static BarCode newDeutschePostIdentcode​(int dist, int customer, int mailing)
      Create a new DeutschePost "IdentCode", a variation on Interleaved 2 of 5 with a (4,9) weighted modulo 10 checkdigit.
      static BarCode newDeutschePostLeitcode​(int pz, int street, int number, int product)
      Create a new DeutschePost "LeitCode", a variation on Interleaved 2 of 5 with a (4,9) weighted modulo 10 checkdigit.
      static BarCode newDeutschePostMatrix​(java.lang.String data, int size)
      Create a new DeutschePost "PostMatrix", which is a DataMatrix code with two locator bars to the left of the symbol.
      static BarCode newDeutschePostMatrix​(java.lang.String mailingnumber, int issuer, int product, int postcode, java.lang.String clientjob, java.lang.String other, int size)
      Create a new DeutschePost "PostMatrix", which is a DataMatrix code with two locator bars to the left of the symbol.
      static BarCode newEAN13​(java.lang.String value)
      Create a new GS1 EAN-13 code at a scale of 80%, giving a symbol an inch wide.
      static BarCode newEAN13​(java.lang.String value, double scale)
      Create a new GS1 EAN-13 code.
      static BarCode newEAN8​(java.lang.String value)
      Create a new GS1 EAN-8 code at a scale of 80%, giving a symbol 3/5th of an inch wide.
      static BarCode newEAN8​(java.lang.String value, double scale)
      Create a new GS1 EAN-8 code at the specified scale.
      static BarCode newIntelligentMail​(java.lang.String value)
      Create a new "Intelligent Mail" BarCode, a 4-state barcode used by the USPS and designed to replace PostNet.
      static BarCode newInterleaved25​(java.lang.String value, boolean checksum)
      Create a new Interleaved 2 of 5 BarCode with an X-unit of 1pt (0.353mm) and a thick/thin ratio of 2.8.
      static BarCode newInterleaved25​(java.lang.String value, boolean checksum, float xunit, float ratio)
      Create a new Interleaved 2 of 5 BarCode.
      static BarCode newITF14​(java.lang.String value, boolean checksum, float xunit, float ratio, boolean verticalBearer)
      Create a new ITF14 BarCode.
      static BarCode newMaxiCode​(int service, java.lang.String postcode, int country, java.lang.String address)
      Create a new MaxiCode representing an address.
      static BarCode newMaxiCode​(int service, java.lang.String postcode, java.lang.String country, java.lang.String address)
      Create a new MaxiCode representing an address.
      static BarCode newMaxiCode​(java.lang.String value, boolean eec)
      Create a new MaxiCode representing an address with the specified message.
      static BarCode newPDF417​(byte[] value, float xunit, int securitylevel, int columns)
      Create a new PDF417 BarCode from binary data.
      static BarCode newPDF417​(java.lang.String value)
      Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437.
      static BarCode newPDF417​(java.lang.String value, float xunit, int securitylevel, int columns)
      Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in ISO-8859-1 (ECI 3).
      static BarCode newPDF417​(java.lang.String value, float xunit, int securitylevel, int columns, int eci)
      Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437 or ISO-8859-1.
      static BarCode newPostnet​(java.lang.String value)
      Create a new PostNet code, a numeric barcode used by the United States Postal Service.
      static BarCode newQRCode​(byte[] value, double modulesize, int ecc, int version)
      Create a new QR-Code which encodes a series of raw bytes.
      static BarCode newQRCode​(java.lang.String value, double modulesize, int ecc, int version)
      Create a new QR-Code, a two-dimensional algorithm as defined in ISO/IEC 18004:2006(E) but originally developed by Denso corporation.
      static BarCode newQRCode​(java.lang.String value, java.lang.String encoding, double modulesize, int ecc, int version)
      Create a new QR-Code which encodes a String in a specified encoding.
      static BarCode newRM4SCC​(java.lang.String value)
      Create a new Royal Mail 4-state Customer Code, an algorithm used by the Royal Mail in the This code can represent the digits 0-9 and the upper case letters A-Z.
      static BarCode newUPCA​(java.lang.String value)
      Create a new UPC-A code at a scale of 80%, giving a symbol an inch wide.
      static BarCode newUPCA​(java.lang.String value, double scale)
      Create a new UPC-A code.
      void setBarHeight​(float height)
      Set the height of the bars used in this symbol.
      void setColor​(java.awt.Paint color)
      Set the color of the BarCode.
      void setFont​(PDFFont font)
      Set the font to be used for text display
      void setHeight​(float height)
      Set the height of this symbol.
      void setInkBleed​(double x, double y)
      Set the ink bleed amount - the number of points the bars are expected to expand in a horizontal and vertical direction due to ink bleed or other quirks of the printing process.
      void setShowText​(boolean show)
      Request that a human-readable version of the barcode value is displayed below the code.
      void setText​(java.lang.String text, PDFFont font)
      Set the text to display under the BarCode.
      void setWidth​(float width)
      Set the width of this symbol.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAXICODE_SHIFTA

        public static final char MAXICODE_SHIFTA
        Represents the MaxiCode "SHIFT-A" control character.
        See Also:
        Constant Field Values
      • MAXICODE_SHIFTB

        public static final char MAXICODE_SHIFTB
        Represents the MaxiCode "SHIFT-B" control character.
        See Also:
        Constant Field Values
      • MAXICODE_SHIFTC

        public static final char MAXICODE_SHIFTC
        Represents the MaxiCode "SHIFT-C" control character.
        See Also:
        Constant Field Values
      • MAXICODE_SHIFTD

        public static final char MAXICODE_SHIFTD
        Represents the MaxiCode "SHIFT-D" control character.
        See Also:
        Constant Field Values
      • MAXICODE_SHIFTE

        public static final char MAXICODE_SHIFTE
        Represents the MaxiCode "SHIFT-E" control character.
        See Also:
        Constant Field Values
      • MAXICODE_TWOSHIFTA

        public static final char MAXICODE_TWOSHIFTA
        Represents the MaxiCode "2 SHIFT-A" control character.
        See Also:
        Constant Field Values
      • MAXICODE_THREESHIFTA

        public static final char MAXICODE_THREESHIFTA
        Represents the MaxiCode "3 SHIFT-A" control character.
        See Also:
        Constant Field Values
      • MAXICODE_LATCHA

        public static final char MAXICODE_LATCHA
        Represents the MaxiCode "LATCH-A" control character.
        See Also:
        Constant Field Values
      • MAXICODE_LATCHB

        public static final char MAXICODE_LATCHB
        Represents the MaxiCode "LATCH-B" control character.
        See Also:
        Constant Field Values
      • MAXICODE_LOCK

        public static final char MAXICODE_LOCK
        Represents the MaxiCode "LOCK-A", "LOCK-B" and "LOCK-C" control characters
        See Also:
        Constant Field Values
      • MAXICODE_GS

        public static final char MAXICODE_GS
        Represents the MaxiCode "Group Seperator" characters (U+001D). This is commonly used when creating addresses for delivery.
        See Also:
        Constant Field Values
      • MAXICODE_RS

        public static final char MAXICODE_RS
        Represents the MaxiCode "Record Seperator" characters (U+001E). This is commonly used when creating addresses for delivery.
        See Also:
        Constant Field Values
      • DATAMATRIX_LATCH_BASE256

        public static final char DATAMATRIX_LATCH_BASE256
        Represents the DataMatrix "Latch to Base256" character. This can be used to switch the DataMatrix code to Base 256 encoding
        Since:
        2.11.4
        See Also:
        Constant Field Values
      • DATAMATRIX_LATCH_C40

        public static final char DATAMATRIX_LATCH_C40
        Represents the DataMatrix "Latch to C40" character. This can be used to switch the DataMatrix code to C40 encoding
        Since:
        2.11.4
        See Also:
        Constant Field Values
      • DATAMATRIX_LATCH_ANSIX12

        public static final char DATAMATRIX_LATCH_ANSIX12
        Represents the DataMatrix "Latch to ANSI X.12" character. This can be used to switch the DataMatrix code to ANSI X.12 encoding
        Since:
        2.11.4
        See Also:
        Constant Field Values
      • DATAMATRIX_LATCH_TEXT

        public static final char DATAMATRIX_LATCH_TEXT
        Represents the DataMatrix "Latch to Text" character. This can be used to switch the DataMatrix code to Text encoding
        Since:
        2.11.4
        See Also:
        Constant Field Values
      • DATAMATRIX_LATCH_EDIFACT

        public static final char DATAMATRIX_LATCH_EDIFACT
        Represents the DataMatrix "Latch to EDIFACT" character. This can be used to switch the DataMatrix code to EDIFACT encoding
        Since:
        2.11.4
        See Also:
        Constant Field Values
      • DATAMATRIX_LATCH_ASCII

        public static final char DATAMATRIX_LATCH_ASCII
        Represents the DataMatrix "Latch to ASCII" character. This can be used to switch the DataMatrix code to ASCII encoding
        Since:
        2.11.4
        See Also:
        Constant Field Values
      • FNC1

        public static final char FNC1
        Represents the FNC1 character, used in a number of barcodes
        Since:
        2.11.17
        See Also:
        Constant Field Values
      • FNC2

        public static final char FNC2
        Represents the FNC1 character, used in a number of barcodes
        Since:
        2.11.17
        See Also:
        Constant Field Values
      • FNC3

        public static final char FNC3
        Represents the FNC1 character, used in a number of barcodes
        Since:
        2.11.17
        See Also:
        Constant Field Values
      • FNC4

        public static final char FNC4
        Represents the FNC1 character, used in a number of barcodes
        Since:
        2.11.17
        See Also:
        Constant Field Values
      • CODE128_SETA

        public static final char CODE128_SETA
        A character than can be used to force the Code 128 barcode to set A
        Since:
        2.14.1
        See Also:
        Constant Field Values
      • CODE128_SETB

        public static final char CODE128_SETB
        A character than can be used to force the Code 128 barcode to set B
        Since:
        2.14.1
        See Also:
        Constant Field Values
      • CODE128_SETC

        public static final char CODE128_SETC
        A character than can be used to force the Code 128 barcode to set C
        Since:
        2.14.1
        See Also:
        Constant Field Values
    • Method Detail

      • newInterleaved25

        public static BarCode newInterleaved25​(java.lang.String value,
                                               boolean checksum)
        Create a new Interleaved 2 of 5 BarCode with an X-unit of 1pt (0.353mm) and a thick/thin ratio of 2.8. This algorithm is only suitable for numbers, and requires an even number of digits (a leading "0" will be automatically added if required).
        Parameters:
        value - the value of the BarCode
        checksum - whether to apply a check digit using the standard (1,3) weighted modulo 10 algorithm
      • newInterleaved25

        public static BarCode newInterleaved25​(java.lang.String value,
                                               boolean checksum,
                                               float xunit,
                                               float ratio)
        Create a new Interleaved 2 of 5 BarCode. This algorithm is only suitable for numbers, and requires an even number of digits (a leading "0" will be automatically added if required).
        Parameters:
        value - the value of the BarCode
        checksum - whether to apply a check digit using the standard (1,3) weighted modulo 10 algorithm
        xunit - the size of the X-Dimension of the barcode, in points - typically about 1
        ratio - the ratio of thick-bar width to thin-bar width - typically between 2 and 3
      • newITF14

        public static BarCode newITF14​(java.lang.String value,
                                       boolean checksum,
                                       float xunit,
                                       float ratio,
                                       boolean verticalBearer)
        Create a new ITF14 BarCode. This is identical to an Interleaved 2-5 barcode, but the text is formatted slightly differently and the optional "bearer bars" can be added. The default height is 32mm (90.35pt)
        Parameters:
        value - the value of the BarCode, which should be 8, 12, 13 digits (if checksum is false) or 9, 13 or 14 digits if checksum is true.
        checksum - whether to apply a check digit using the standard (1,3) weighted modulo 10 algorithm
        xunit - the xunit size in points, which should be 2.89 (1.02mm) for a 100% magnification ITF-14, although this can be scaled up or down as required.
        ratio - the ratio of thick-bar width to thin-bar width - GS1 specifies 2.5, and this value should be used unless you know better. Recommended values are between 2.25 and 3
        verticalBearer - if true, the vertical bearers will be included in the symbol as well as the mandatory horizontal bearer bars.
      • newDeutschePostLeitcode

        public static BarCode newDeutschePostLeitcode​(int pz,
                                                      int street,
                                                      int number,
                                                      int product)
        Create a new DeutschePost "LeitCode", a variation on Interleaved 2 of 5 with a (4,9) weighted modulo 10 checkdigit.
        Parameters:
        pz - the postal zone (5 digits)
        street - the street number (3 digits)
        number - the house number (3 digits)
        product - the product number (2 digits)
      • newDeutschePostIdentcode

        public static BarCode newDeutschePostIdentcode​(int dist,
                                                       int customer,
                                                       int mailing)
        Create a new DeutschePost "IdentCode", a variation on Interleaved 2 of 5 with a (4,9) weighted modulo 10 checkdigit.
        Parameters:
        dist - the distribution center code (2 digits)
        customer - the customer number (3 digits)
        mailing - the mailing number (6 digits)
      • newDeutschePostCode

        public static BarCode newDeutschePostCode​(java.lang.String value)
        Create a new DeutschePost Interleaved 2 of 5 code. This algorithm is only suitable for numbers, and requires an odd number of digits (a leading "0" will be automatically added if required). A (4,9) weighted modulo-10 checkdigit will be added.
        Parameters:
        value - the value of the BarCode
      • newCode39

        public static BarCode newCode39​(java.lang.String value,
                                        boolean checksum)
        Create a new Code 3 of 9 code with an X-unit of 1 and a thick/thin bar ratio of 2.8. This algorithm can display digits, the 26 upper-case letters, the space character and the symbols '-', '+', '/', '.', '$' and '%'.
        Parameters:
        value - the value of the BarCode
        checksum - whether to apply the standard Code 3 of 9 checksum algorithm
      • newCode39

        public static BarCode newCode39​(java.lang.String value,
                                        boolean checksum,
                                        float xunit,
                                        float ratio)
        Create a new Code 3 of 9 code. This algorithm can display digits, the 26 upper-case letters, the space character and the symbols '-', '+', '/', '.', '$' and '%'.
        Parameters:
        value - the value of the BarCode
        checksum - whether to apply the standard Code 3 of 9 checksum algorithm
        xunit - the size of the X-Dimension of the barcode, in points - typically about 1
        ratio - the ratio of thick-bar width to thin-bar width - typically between 2 and 3
      • newCode39Extended

        public static BarCode newCode39Extended​(java.lang.String value,
                                                boolean checksum)
        Create a new Extended Code 3 of 9 ("Code 39+") code with an X-unit of 1pt (0.353mm) and a thick/thin bar ratio of 2.8 This algorithm uses the same symbology as Code 3 of 9 but can display all ASCII characters. The re-encoding algorithm is described on this page.
        Parameters:
        value - the value of the BarCode
        checksum - whether to apply the standard Code 3 of 9 checksum algorithm
      • newCode39Extended

        public static BarCode newCode39Extended​(java.lang.String value,
                                                boolean checksum,
                                                float xunit,
                                                float ratio)
        Create a new Extended Code 3 of 9 ("Code 39+") code. This algorithm uses the same symbology as Code 3 of 9 but can display all ASCII characters. The re-encoding algorithm is described on this page.
        Parameters:
        value - the value of the BarCode
        checksum - whether to apply the standard Code 3 of 9 checksum algorithm
        xunit - the size of the X-Dimension of the barcode, in points - typically about 1
        ratio - the ratio of thick-bar width to thin-bar width - typically between 2 and 3
      • newCode93

        public static BarCode newCode93​(java.lang.String value,
                                        float xunit)
        Create a new Code 93 code. This symbology uses a similar encoding to Code 3 of 9 but with a more efficient variable-width encoding and includes two checkdigits. It can encode all ASCII characters from U+0000 to U+007F. The two check digits will be calculated and added automatically.
        Parameters:
        value - the value of the BarCode
        xunit - the size of the X-Dimension of the barcode, in points - typically about 1
        Since:
        2.11.20
      • newUPCA

        public static BarCode newUPCA​(java.lang.String value)

        Create a new UPC-A code at a scale of 80%, giving a symbol an inch wide. The UPC-A code is identical to EAN-13 in every respect, except that the leading zero digit in the accompanying text is not normally printed. The symbol generated by this method is identical to calling newEAN13("0" + value).

        If the value supplied is greater than 11 digits, a supplemental code will be included which may be 2 or 5 digits long

        Parameters:
        value - the value of the BarCode - 11, 12, 13, 14, 16 or 17 digits (if 11, 13 or 16 the check digit will be appended)
        Since:
        2.22.1
      • newEAN13

        public static BarCode newEAN13​(java.lang.String value)

        Create a new GS1 EAN-13 code at a scale of 80%, giving a symbol an inch wide. An EAN-13 code represents a 13 digit number - broadly speaking, the first 7 digits are the country and manufacturer code, the next 5 digits are the product code, and the final digit the checksum. The 12 digit UPC-A barcodes as used in the USA are just EAN-13 codes with a leading "0".

        If the value supplied is greater than 13 digits, a supplemental code will be included which may be 2 or 5 digits long

        Parameters:
        value - the value of the BarCode - 12, 13, 14, 15, 17 or 18 digits (if 12, 14 or 17 the check digit will be appended)
      • newEAN13

        public static BarCode newEAN13​(java.lang.String value,
                                       double scale)

        Create a new GS1 EAN-13 code. An EAN-13 code represents a 13 digit number - broadly speaking, the first 7 digits are the country and manufacturer code, the next 5 digits are the product code, and the final digit the checksum. The 12 digit UPC-A barcodes as used in the USA are just EAN-13 codes with a leading "0".

        If the value supplied is greater than 13 digits, a supplemental code will be included which may be 2 or 5 digits long

        Parameters:
        value - the value of the BarCode - 12, 13, 14, 15, 17 or 18 digits (if 12, 14 or 17 the check digit will be appended)
        scale - the scale of the code - typically from 0.8 to 2, representing 80% to 200% scale. A value of 1 results in an X-dimension of 0.936pt (0.33mm).
      • newUPCA

        public static BarCode newUPCA​(java.lang.String value,
                                      double scale)

        Create a new UPC-A code. The UPC-A code is identical to EAN-13 in every respect, except that the leading zero digit in the accompanying text is not normally printed. The symbol generated by this method is identical to calling newEAN13("00" + value, scale).

        If the value supplied is greater than 12 digits, a supplemental code will be included which may be 2 or 5 digits long

        Parameters:
        value - the value of the BarCode - 11, 12, 13, 14, 16 or 17 digits (if 11, 13 or 16 the check digit will be appended)
        scale - the scale of the code - typically from 0.8 to 2, representing 80% to 200% scale. A value of 1 results in an X-dimension of 0.936pt (0.33mm).
        Since:
        2.22.1
      • newEAN8

        public static BarCode newEAN8​(java.lang.String value)

        Create a new GS1 EAN-8 code at a scale of 80%, giving a symbol 3/5th of an inch wide. An EAN-13 code represents an 8 digit number - the last digit is a check digit. It's essentially a cut-down EAN-13 code.

        If the value supplied is greater than 8 digits, a supplemental code will be included which may be 2 or 5 digits long

        Parameters:
        value - the value - a 7, 8, 9, 10, 12 or 13 digit number (if 7, 9 or 12 the check digit will be appended automatically)
        Since:
        2.11.8
      • newEAN8

        public static BarCode newEAN8​(java.lang.String value,
                                      double scale)

        Create a new GS1 EAN-8 code at the specified scale.

        If the value supplied is greater than 8 digits, a supplemental code will be included which may be 2 or 5 digits long

        Parameters:
        value - the value - a 7, 8, 9, 10, 12 or 13 digit number (if 7, 9 or 12 the check digit will be appended automatically)
        scale - the scale of the code - typically from 0.8 to 2, representing 80% to 200% scale. A value of 1 results in an X-dimension of 0.936pt (0.33mm).
        Since:
        2.11.8
      • newCodabar

        public static BarCode newCodabar​(java.lang.String value,
                                         float xunit)
        Create a new Codabar BarCode. Codabar is an elderly symbology that can represent digits and the letters A, B, C, D, E, N, T or * which must be used as start/end letters of the code.
        Parameters:
        value - the value of the BarCode
        xunit - the size of the X-Dimension of the barcode, in points - typically about 1
      • newCode128

        public static BarCode newCode128​(java.lang.String value)
        Create a new Code-128 BarCode with an X-unit of 1pt (0.353mm)
        Parameters:
        value - the value of the BarCode
        See Also:
        newCode128(String, double)
      • newCode128

        public static BarCode newCode128​(java.lang.String value,
                                         double xunit)

        Create a new Code-128 BarCode. This code can display digits, upper and lower-case letters and most punctuation characters from the U+0000 - U+007E (US-ASCII) range. A checksum is automatically included as part of the barcode.

        Code 128 has three "character sets" - A, B or C - which encode different subsets of characters. At any time during the encoding process, a subset can be chosen by embedding the characters CODE128_SETA, CODE128_SETB or CODE128_SETC into the String being encoded, to switch to set A, B or C respectively. Generally this is not required: if no character set is specified, the most appropriate combination will be used. So, for example, to force a String to be encoded using set A, you could specify the string BarCode.CODE128_SETA + "CODEHERE".

        GS1 EAN-128 barcodes can be created by using FNC1 for the FNC1 control character, and the FNC2, FNC3 and FNC4 characters can also be used if required. Here's an example of how to create a GS1 barcode with the following data (see section 3 of the GS1 specification for an explanation of the fields):

        • Item Number: 19421123450011
        • Best Before date: 991231
        • Batch Number: 101234
         StringBuilder sb = new StringBuilder();
         sb.append(BarCode.FNC1);
         sb.append("01");         // "Global Trade Item Number (GTIN)" application identifier
         sb.append("19421123450011");
         sb.append(BarCode.FNC1);
         sb.append("15");         // "Best Before Date" application identifier
         sb.append("991231");
         sb.append(BarCode.FNC1);
         sb.append("10");         // "Batch or Lot Number" application identifier
         sb.append("101234");
         BarCode code = BarCode.newCode128(sb.toString(), 1.4);
         

        Note: in previous releases the \n character was repurposed to mean FNC1, which caused problems when a literal \n (valid in Code128 set C) was required. For clarity the functionality has been removed and since 2.11.12, FNC1 is the only way to specify FNC1.

        Parameters:
        value - the value of the BarCode
        xunit - The size of the X-Dimension of the barcode in points. GS1-128 codes recommend an X-unit of 1.4pt (0.495mm)
      • newPostnet

        public static BarCode newPostnet​(java.lang.String value)
        Create a new PostNet code, a numeric barcode used by the United States Postal Service. This algorithm encodes information in the height of the bars, so the overall height is fixed to 9 points.
        Parameters:
        value - the value of the BarCode
      • newRM4SCC

        public static BarCode newRM4SCC​(java.lang.String value)
        Create a new Royal Mail 4-state Customer Code, an algorithm used by the Royal Mail in the This code can represent the digits 0-9 and the upper case letters A-Z. This algorithm encodes information in the height of the bars, so the overall height is fixed to 25 points (this includes the 2mm quiet zone top and bottom).
        Parameters:
        value - the value of the BarCode
      • newAusPost4S

        public static BarCode newAusPost4S​(java.lang.String value)
        Create a new Australia Post 4-state Barcode. This code accepts either an eight digit number (the sorting code) or a ten-digit number (the sorting code with a "11" prefix) This algorithm encodes information in the height of the bars, so the overall height is fixed to 26 points (this includes the 2mm quiet zone top and bottom).
        Parameters:
        value - a value, which must be 8 or 10 digits long
        Since:
        2.28.3
      • newIntelligentMail

        public static BarCode newIntelligentMail​(java.lang.String value)
        Create a new "Intelligent Mail" BarCode, a 4-state barcode used by the USPS and designed to replace PostNet.
        Parameters:
        value - a String of digits 20, 25, 29 or 31 digits long
        Since:
        2.10.4
      • newPDF417

        public static BarCode newPDF417​(java.lang.String value)
        Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437. This method is identical to calling the method below with xunit=1, securitylevel=-1, columns=0 and eci=3, meaning an auto-sized symbol wtih an X-dimension of 1pt (0.353mm) that matches the encoding in the latest version of the specification.
        Parameters:
        value - the value of the BarCode
        See Also:
        newPDF417(String, float, int, int)
      • newPDF417

        public static BarCode newPDF417​(java.lang.String value,
                                        float xunit,
                                        int securitylevel,
                                        int columns)
        Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in ISO-8859-1 (ECI 3). See the method below for more details - this method calls that with eci=3, as defined in the latest version of the specification
      • newPDF417

        public static BarCode newPDF417​(java.lang.String value,
                                        float xunit,
                                        int securitylevel,
                                        int columns,
                                        int eci)

        Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437 or ISO-8859-1. The code includes a variable degree of error correction - the recommended maximum is roughly 1600 ASCII characters or 1900 digits and the absolute maximum with no error correction is roughly 1800 ASCII characters of 2700 digits. The Compact, ECI and Macro extensions to PDF417 are not supported.

        For reasons we cannot understand, the ISO specification for the PDF417 barcode changed between the 2001 and 2006 revisions. In 2001, the default encoding of binary characters referenced codepage 437, a pre-unicode but still perfectly valid way of encoding certain characters outside the ASCII range. In 2006, the default encoding was changed to ISO8859-1. While it's possible to specify the encoding explicitly in the barcode via an ECI (Extended Channel Interpretation), this is an optional part of the specification and not supported by some encoders.

        This means if you are creating a PDF417 barcode with characters outside of the binary range, you are forced to choose between one of the following options.

        1. Target the default encoding as it was specified in 2001; your barcode will scan incorrectly on later equipment (specify eci=2)
        2. Target the default encoding as it was specified in 2006; your barcode will scan incorrectly on earlier equipmen (specify eci=3).
        3. Specify the encoding explicitly; your barcode will scan incorrectly on equipment that doesn't handle ECI codes (specify eci=-1).

        Until 2.20.2 our PDF417 API (written in 2004) handled only the first option, but we now offer all of the options above via the "eci" parameter. If you're using non-ASCII characters, frankly, we'd suggest you use another methodology if possible, otherwise try to determine which version of the specification your barcode readers are using. You have been warned. The PDF417 methods in this API that predate this change have to choose one approach to standardise on, and we've chosen to target the latest version of the specification by default. This will mean a change for anyone encoding binary data with an earlier release of this API, but increased compatibility going forward.

        For barcodes that only make use of US ASCII characters, there is no change to functionality and any ECI value may be specified. We suggest a value of 3

        Parameters:
        value - the value of the BarCode
        xunit - the X-dimension of the barcode in points - typically around 1
        securitylevel - how much error correction to apply: -1 to choose an appropriate level or a value from 0 (none) to 8 (512 bytes of error correction). Recommended values are 2 for up to about 70 characters, 3 for up to about 200, 4 for up to about 400 and 5 for more. Remember setting this too high for large volumes of text may cause the maxiumum number of codewords to be reached, which will cause an exception.
        columns - the number of data codeword columns in the code - a value greater than 0 will fix the width of the code and allow only the height to vary, whereas 0 will allow the code to auto-size to fit the available space (recommended).
        eci - the value of the "Extended Channel Interpretation"; "2" for the 2001 version, "3" for the 2006 or 2015 verions, or "-1" to encode the appropriate ECI explicitly in the barcode (in this case we'll typically use ECI 3). This parameter will have no effect unless characters outside the US-ASCII range are to be encoded.
        Since:
        2.20.2
      • newPDF417

        public static BarCode newPDF417​(byte[] value,
                                        float xunit,
                                        int securitylevel,
                                        int columns)
        Create a new PDF417 BarCode from binary data. This method simply calls newPDF417(new String(bytes, "ISO-8859-1"), xunit, securityleve, columns, 3)
        Parameters:
        value - the value of the BarCode.
        xunit - the X-dimension of the barcode in points - typically around 1
        securitylevel - how much error correction to apply: -1 to choose an appropriate level or a value from 0 (none) to 8 (512 bytes of error correction). Recommended values are 2 for up to about 70 characters, 3 for up to about 200, 4 for up to about 400 and 5 for more. Remember setting this too high for large volumes of text may cause the maxiumum number of codewords to be reached, which will cause an exception.
        columns - the number of data codeword columns in the code - a value greater than 0 will fix the width of the code and allow only the height to vary, whereas 0 will allow the code to auto-size to fit the available space (recommended).
      • newMaxiCode

        public static BarCode newMaxiCode​(java.lang.String value,
                                          boolean eec)
        Create a new MaxiCode representing an address with the specified message. MaxiCode is a two-dimensional algorithm originally developed by UPS, with a fixed size of 80x80 points. It may encode up to 93 alphanumeric characters from ISO-8859-1 or 138 digits, encoded using several "Code Sets". Typically an appropriate set will be chosen automatically, but for more control the control characters like MAXICODE_SHIFTA, MAXICODE_LATCHB and MAXICODE_LOCK may be inserted directly into the value.
        Parameters:
        value - the value of the BarCode
        eec - whether to use Extended Error Correction (mode 5).
      • newMaxiCode

        public static BarCode newMaxiCode​(int service,
                                          java.lang.String postcode,
                                          int country,
                                          java.lang.String address)
        Create a new MaxiCode representing an address. Both numeric and alphanumeric postcodes can be supplied, which will result in mode 2 or 3 MaxiCodes respectively. For example, to create a MaxiCode for a Belgian delivery address.
         BarCode code = BarCode.newMaxiCode(999, "B1050", 57,
             "Comité Européean de Normalisation"+BarCode.MAXICODE_GS+
             "rue de Stassart 36"+BarCode.MAXICODE_GS+"Bruxelles");
         
        Parameters:
        service - the service level, from 1 to 999
        postcode - the postcode of the address, either up to nine numeric digits or up to six alphanumeric digits
        country - the numeric ISO-3166 country code
        address - the address to place in the secondary message. Lines in the address should be separated with the MAXICODE_GS character.
      • newMaxiCode

        public static BarCode newMaxiCode​(int service,
                                          java.lang.String postcode,
                                          java.lang.String country,
                                          java.lang.String address)
        Create a new MaxiCode representing an address. As for newMaxiCode(int, String, int, String) but the country is be specified as a two-letter ISO-3166 country code. For example, to create a MaxiCode for a US address:
         BarCode code = BarCode.newMaxiCode(1, "524032140", "US",
             "AIM USA"+BarCode.MAXICODE_GS+"634 ALPHA DRIVE"+BarCode.MAXICODE_GS+"PITTSBURGH PA");
         
        Parameters:
        service - the service level, from 1 to 999
        postcode - the postcode of the address, either up to nine numeric digits or up to six alphanumeric digits
        country - the two-letter ISO-3166 country code
        address - the address to place in the secondary message. Lines in the address should be separated with the MAXICODE_GS character.
      • newQRCode

        public static BarCode newQRCode​(java.lang.String value,
                                        double modulesize,
                                        int ecc,
                                        int version)
        Create a new QR-Code, a two-dimensional algorithm as defined in ISO/IEC 18004:2006(E) but originally developed by Denso corporation. It can encode up to 7089 numeric characters, 4296 alphanumeric latin or 1817 Japanese characters from the ISO-8859-1 and Shift-JIS character set (ie. all Latin and Japanese characters). It can be scanned in high speed in any direction and at the time of writing is the most information-dense format available. The "Structured Append" mode is not supported.
        Parameters:
        value - the value of the BarCode
        modulesize - The size of a module in mm. This value depends on the scanning device, but recommended absolute minimum values for 600dpi printing are 0.17, 0.21 or 0.25mm. 0.5mm seems to be fairly typical.
        ecc - the level of error correction, from 1 (lowest) to 4 (highest) offering 7%, 15%, 25% and 30% redundancy respectively. If in doubt we recommend 2.
        version - the "version" or size of the code - 0 to auto-size, or a value from 1 to 40.
      • newQRCode

        public static BarCode newQRCode​(byte[] value,
                                        double modulesize,
                                        int ecc,
                                        int version)
        Create a new QR-Code which encodes a series of raw bytes. Up to 2593 bytes may be encoded.
        Parameters:
        value - the value of the BarCode - up to 2593 bytes.
        modulesize - The size of a module in mm. This value depends on the scanning device, but recommended absolute minimum values for 600dpi printing are 0.17, 0.21 or 0.25mm. 0.5mm seems to be fairly typical.
        ecc - the level of error correction, from 1 (lowest) to 4 (highest) offering 7%, 15%, 25% and 30% redundancy respectively. If in doubt we recommend 2.
        version - the "version" or size of the code - 0 to auto-size, or a value from 1 to 40.
        See Also:
        newQRCode(String, double, int, int)
      • newQRCode

        public static BarCode newQRCode​(java.lang.String value,
                                        java.lang.String encoding,
                                        double modulesize,
                                        int ecc,
                                        int version)
        Create a new QR-Code which encodes a String in a specified encoding. QR-Codes generated in this way are suitable for use in closed systems, where the encoding has been agreed in advance. In practice, UTF-8 is the most common choice.
        Parameters:
        value - the value of the BarCode
        encoding - the encoding to use to encode the BarCode bytes
        modulesize - The size of a module in mm. This value depends on the scanning device, but recommended absolute minimum values for 600dpi printing are 0.17, 0.21 or 0.25mm. 0.5mm seems to be fairly typical.
        ecc - the level of error correction, from 1 (lowest) to 4 (highest) offering 7%, 15%, 25% and 30% redundancy respectively. If in doubt we recommend 2.
        version - the "version" or size of the code - 0 to auto-size, or a value from 1 to 40.
        Since:
        2.11.14
        See Also:
        newQRCode(String, double, int, int)
      • newDataMatrixCode

        public static BarCode newDataMatrixCode​(java.lang.String data)

        Create a new Data Matrix code. Data Matrix is a public domain two-dimensional algorithm which encodes data using one of several algorithms, and can store up to 2,335 characters. By default an appropriate size and algorithm is chosen, but for more control the various Data Matrix Latch characters can be inserted into the String you're encoding to set the algorithm.

        This method will choose an appropriate symbol size for the data. Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.

        Parameters:
        data - the value of the BarCode
        Since:
        2.11.4
      • newDataMatrixCode

        public static BarCode newDataMatrixCode​(java.lang.String data,
                                                int rows,
                                                int cols)

        Create a new Data Matrix code of the specified dimensions. Data Matrix is a public domain two-dimensional algorithm which encodes data using one of several algorithms, and can store up to 2,335 characters. By default an appropriate algorithm is chosen, but for more control the various DataMatrix Latch characters can be inserted into the String you're encoding to set the algorithm.

        The supplied dimensions will be used if possible, but if not the symbol will be sized automatically to accodate the data.

        Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.

        Parameters:
        data - the value of the BarCode
        rows - the number of rows in the barcode, or 0 to auto-size
        cols - the number of rows in the barcode, or 0 to auto-size
        Since:
        2.11.4
      • newDataMatrixCode

        public static BarCode newDataMatrixCode​(byte[] data,
                                                int rows,
                                                int cols)

        Create a new Data Matrix code representing binary data. Data Matrix is a public domain two-dimensional algorithm which encodes data using one of several algorithms, and can store up to 2,335 characters.

        This method will choose an appropriate symbol size for the data. Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.

        Parameters:
        data - the value of the BarCode, which will be encoded as binary data
        rows - the number of rows in the barcode, or 0 to auto-size
        cols - the number of rows in the barcode, or 0 to auto-size
        Since:
        2.11.25
      • newDeutschePostMatrix

        public static BarCode newDeutschePostMatrix​(java.lang.String data,
                                                    int size)
        Create a new DeutschePost "PostMatrix", which is a DataMatrix code with two locator bars to the left of the symbol.
        Parameters:
        data - the value of the BarCode - this must be a valid Deutsche Post barcode value, as described in the RESPONSEPLUS Ausprägung Antwort specification, eg e.g. DEAW00A01Z690RA51251496008010205001099~JOB4711~850
        size - the number of rows/cols in the barcode - 0 to autosize, otherwise valid values are 22 or 26
        Since:
        2.16.2
      • newDeutschePostMatrix

        public static BarCode newDeutschePostMatrix​(java.lang.String mailingnumber,
                                                    int issuer,
                                                    int product,
                                                    int postcode,
                                                    java.lang.String clientjob,
                                                    java.lang.String other,
                                                    int size)
        Create a new DeutschePost "PostMatrix", which is a DataMatrix code with two locator bars to the left of the symbol.
        Parameters:
        mailingnumber - the Unique issuer mailing ID (Field C, Eindeutige Sendungs-ID des Herausgebers), a 9-character String of digits or upper-case letters
        issuer - the issuer id (Field D, Herausgeber) - the first 8 digits of the UCP client number or EKP-Kundennumme
        product - the product key (Field E, Produktschlüssel), which will be formatted as a 5 digit number
        postcode - the German postcode of the destinationi (Field N, Postleitzahl)
        clientjob - the client job reference (Field T, Kundenauftragsnummer des Herausgebers (AM)), a String of up to 15 digits or upper-case letters.
        other - the optional additional information field (Field V, Sonstige Informationen des Herausgebers), which may be up to 15 digits or upper-case letters if specified.
        size - the number of rows/cols in the barcode - 0 to autosize, otherwise valid values are 22 or 26
        Since:
        2.16.2
      • newDataMatrixCode

        public static BarCode newDataMatrixCode​(java.lang.String data,
                                                int rows,
                                                int cols,
                                                char encoder)

        Create a new Data Matrix code using the specified dimensions and encoder. This method allows you to specify the encoding algorithm for the symbol, which may be one of the Latch characters. The dimensions may also be specified, or values of 0 can be used to auto-size the symbol.

        Data Matrix does not specify a minimum or maximum absolute symbol size, so the canvas returned from this method has a "pixel" size of 1pt and it may be scaled as necessary.

        Parameters:
        data - the value of the BarCode
        rows - the number of rows in the barcode
        cols - the number of rows in the barcode
        encoder - one of DATAMATRIX_LATCH_BASE256, DATAMATRIX_LATCH_C40, DATAMATRIX_LATCH_TEXT, DATAMATRIX_LATCH_ASCII, DATAMATRIX_LATCH_ANSIX12 or DATAMATRIX_LATCH_EDIFACT
        Since:
        2.11.4
      • newAztecCode

        public static BarCode newAztecCode​(java.lang.String data)
        Create a new Aztec code representing the specified String. Aztec code (defined in ISO24778) is a two-dimensional barcode that can encode up to approximately 3000 ISO-8859-1 characters in a relatively compact square form. It requires no surrounding quiet zone and can be easily scanned in any direction (note: currently the "binary shift" mode is not supported)
        Since:
        2.11.14
      • newDatabar

        public static BarCode newDatabar​(boolean linkage,
                                         java.lang.String value,
                                         boolean truncated,
                                         boolean stacked)

        Create a new GS1 Databar (formerly known as RSS-14) barcode. Databar is defined in ISO/IEC 24724 and can represent a 14-digit GS1 item identification, although at present only the basic linear variant is supported: the "linkage" facility (where the linear barcode is combined with a MicroPDF417 2D code to form an EAN.UCC composite code) is unsupported.

        Also unsupported is the "stacked" variation, although both these flags exist on the method for future compatibility.

        The returned barcode is a fixed size of 96x33 points, or 96x13 points if the "truncated" option is set - uniquely, this symbology requires no quiet zones.

        Parameters:
        linkage - the "linkage" flag. Currently the only supported value is false
        value - the value, which must be 13 or 14 digits (the 14th being the GS1 checkdigit - if missing this will be calculated)
        truncated - if true, the returned barcode will be 13 modules high, rather than the normal 33
        stacked - if true, the barcode will be stacked. Currently the only supported value is false
        Since:
        2.19
      • setInkBleed

        public void setInkBleed​(double x,
                                double y)
        Set the ink bleed amount - the number of points the bars are expected to expand in a horizontal and vertical direction due to ink bleed or other quirks of the printing process. A negative number will reduce the bar by the specified amount and a positive number will increase it. Typically this can be left at zero.
        Parameters:
        x - the number of points to adjust the bar width by
        y - the number of poitns to adjust the bar height by.
        Since:
        2.10.2
      • setColor

        public void setColor​(java.awt.Paint color)
        Set the color of the BarCode. A value of null uses the default color, which is black in the GrayScale colorspace
        Since:
        2.10.3
      • getWidth

        public float getWidth()
        Return the width of the symbol. This will include any mandatory quiet zone required by the algorithm, and will match the width of the canvas returned by getCanvas()
      • getContentRectangle

        public java.awt.geom.Rectangle2D getContentRectangle()
        Return the location of the actual barcode in the Canvas, excluding any quiet-zone or text. The returned parameter are measured from the top-left of the canvas
        Since:
        2.17.1
      • setWidth

        public void setWidth​(float width)
        Set the width of this symbol. Not all symboligies can be resized, and for some (specifically: MaxiCode, Intelligent Mail, Royal Mail, Postnet, EAN-13, EAN-8) this method will throw an * IllegalArgumentException. For other algorithms, this will request the size of the symbol is set to no larger than the specified width (the actual * width chosen result may be smaller). This method will also increase the height of the barcode to at least that returned by getMinimumHeight(). For square codes like QR-Code and Aztec code, setting thw width also sets the height.
        Parameters:
        width - the requested width of the symbol in points.
      • getMinimumHeight

        public float getMinimumHeight()
        Return the recommended minimum height for this symbol. The height for most codes is a function of the width, and will also include additional space if text is to be displayed with the symbol. Although codes with heights less than this height may (depending on symbology) be created, they are not guaranteed to be readable by an open system implementation.
        Since:
        2.10
      • setShowText

        public void setShowText​(boolean show)

        Request that a human-readable version of the barcode value is displayed below the code. Not all codes support this - none of the two-dimensional codes do, for instance. Altering this value will alter the value returned from getHeight() and getMinimumHeight().

        Since 2.23.1 this will call setText() with either the text supplied to the constructor method, or null if show=false

      • setText

        public void setText​(java.lang.String text,
                            PDFFont font)
        Set the text to display under the BarCode. This method can be used to format the value in a different way to the value supplied to the constructor method, although it only works for some formats:
        • Royal Mail Four-state, Postnet or 2D barcodes: no text is possible
        • EAN13 and EAN8 - the default text will always be used
        • Anything else - custom text can be specified
        The text will not wrap and should be narrower than the width of the symbol.
        Parameters:
        text - the text to display, or null to display no text
        font - the font to use for text display, or null use the default font
        Since:
        2.23.1
      • getText

        public java.lang.String getText()
        Return the value of the text content that will be shown below the BarCode. For some formats this will always be null.
        Since:
        2.23.8
      • setFont

        public void setFont​(PDFFont font)
        Set the font to be used for text display
        Parameters:
        font - the font to use for text display, or null use the default font
        Since:
        2.23.8
      • getHeight

        public float getHeight()
        Return the height of the symbol. This will include space for the quiet zone and any text if setShowText(boolean) is true, and the returned value will match the height of the canvas returned by getCanvas().
      • setHeight

        public void setHeight​(float height)
        Set the height of this symbol. The specified value should be more than the value returned by getMinimumHeight(). Not all symbologies can have their height adjusted (specifically: MaxiCode, Intelligent Mail, Royal Mail, Postnet), and this method may throw an IllegalArgumentException if that is the case.
        Parameters:
        height - the full height of the canvas to be returned by getCanvas(), in points.
      • setBarHeight

        public void setBarHeight​(float height)
        Set the height of the bars used in this symbol. Unike setHeight(float), this method directly sets the height of the scannable bars only. The height of the overall BarCode will be taller than this if the setShowText(boolean) method is true and (for ITF14) if bearer bars are used
        Since:
        2.24.4
      • getCanvas

        public PDFCanvas getCanvas()
        Return a new PDFCanvas containing the barcode. The dimensions will match those returned by getWidth() and getHeight(). Although we suggest drawing it onto the page at the size it's returned, it is possible to stretch the canvas to suit.
         PDFCanvas canvas = barcode.getCanvas();
         page.drawCanvas(canvas, x, y, x+canvas.getWidth(), y+canvas.getHeight()):
         
        Since:
        2.10
      • getBufferedImage

        public java.awt.image.BufferedImage getBufferedImage​(double scale,
                                                             java.awt.Paint background)

        Create the BarCode as a BufferedImage. This is a convenience method, nothing to do with PDF but as the hard work creating the barcodes was already done it's an easy addition. For example, here's code to create a BarCode as a PNG:

         BarCode barcode = BarCode.newPDF417("Testing");
         BufferedImage image = barcode.getBufferedImage(0, Color.white);
         ImageIO.write(image, "png", new File("barcode.png"));
         
        versus the equivalent code in a PDF
         BarCode barcode = BarCode.newPDF417("Testing");
         PDF pdf = new PDF();
         PDFCanvas can = barcode.getCanvas();
         PDFPage page = pdf.newPage((int)can.getWidth(), (int)can.getHeight());
         page.drawCanvas(can, 0, 0, page.getWidth(), page.getHeight());
         pdf.render(new FileOutputStream("barcode.pdf"));
         

        Note without a valid license, the barcode will have "DEMO" written overtop"

        Parameters:
        scale - how much to scale the barcode, or zero to auto-size. QR-Codes are measured in millimeters rather than points, so this number should be a factor of 0.70556
        background - the color to paint the background of the image - pass in null to render to a transparent background.
        Since:
        2.11.8