org.faceless.pdf2

## Class BarCode

- java.lang.Object
- - org.faceless.pdf2.BarCode

-     public class BarCode
      extends 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 and 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 and Description
    --- | ---
    `BufferedImage` | `getBufferedImage(double scale, Paint background)` Create the BarCode as a `BufferedImage`.
    `PDFCanvas` | `getCanvas()` Return a new `PDFCanvas` containing the barcode.
    `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.
    `float` | `getWidth()` Return the width of the symbol.
    `static BarCode` | `newAztecCode(String data)` Create a new Aztec code representing the specified String.
    `static BarCode` | `newCodabar(String value, float xunit)` Create a new Codabar BarCode.
    `static BarCode` | `newCode128(String value)` Create a new Code-128 BarCode with an X-unit of 1pt (0.353mm)
    `static BarCode` | `newCode128(String value, double xunit)` Create a new Code-128 BarCode.
    `static BarCode` | `newCode39(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(String value, boolean checksum, float xunit, float ratio)` Create a new Code 3 of 9 code.
    `static BarCode` | `newCode39Extended(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(String value, boolean checksum, float xunit, float ratio)` Create a new Extended Code 3 of 9 ("Code 39+") code.
    `static BarCode` | `newCode93(String value, float xunit)` Create a new Code 93 code.
    `static BarCode` | `newDataMatrixCode(byte[] data, int rows, int cols)` Create a new Data Matrix code representing binary data.
    `static BarCode` | `newDataMatrixCode(String data)` Create a new Data Matrix code.
    `static BarCode` | `newDataMatrixCode(String data, int rows, int cols)` Create a new Data Matrix code of the specified dimensions.
    `static BarCode` | `newDataMatrixCode(String data, int rows, int cols, char encoder)` Create a new Data Matrix code using the specified dimensions and encoder.
    `static BarCode` | `newDeutschePostCode(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(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(String mailingnumber, int issuer, int product, int postcode, String clientjob, 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(String value)` Create a new GS1 EAN-13 code at a scale of 80%, giving a symbol an inch wide.
    `static BarCode` | `newEAN13(String value, double scale)` Create a new GS1 EAN-13 code.
    `static BarCode` | `newEAN8(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(String value, double scale)` Create a new GS1 EAN-8 code at the specified scale.
    `static BarCode` | `newIntelligentMail(String value)` Create a new "Intelligent Mail" BarCode, a 4-state barcode used by the USPS and designed to replace `PostNet`.
    `static BarCode` | `newInterleaved25(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(String value, boolean checksum, float xunit, float ratio)` Create a new Interleaved 2 of 5 BarCode.
    `static BarCode` | `newMaxiCode(int service, String postcode, int country, String address)` Create a new MaxiCode representing an address.
    `static BarCode` | `newMaxiCode(int service, String postcode, String country, String address)` Create a new MaxiCode representing an address.
    `static BarCode` | `newMaxiCode(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(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(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 Windows Codepage CP437.
    `static BarCode` | `newPostnet(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(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(String value, String encoding, double modulesize, int ecc, int version)` Create a new QR-Code which encodes a String in a specified encoding.
    `static BarCode` | `newRM4SCC(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.
    `void` | `setColor(Paint color)` Set the color of the BarCode.
    `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` | `setWidth(float width)` Set the width of this symbol.

    - ### Methods inherited from class java.lang.Object

      `equals, 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(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(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

    - #### 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(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(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(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(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(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(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

    - #### newEAN13

          public static BarCode newEAN13(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(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).

    - #### newEAN8

          public static BarCode newEAN8(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(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(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(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(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(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(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

    - #### newIntelligentMail

          public static BarCode newIntelligentMail(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(String value)

      Create a new PDF417 BarCode, a two-dimensional code defined in ISO15438 which can represent any character in Windows Codepage CP437. An appropriate level of error correction and aspect ratio are chosen automatically, and the X-Dimension is set to 1pt (0.353mm)
      Parameters:
        `value` - the value of the BarCode
      See Also:
        `newPDF417(String, float, int, int)`

    - #### newPDF417

          public static BarCode newPDF417(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 Windows Codepage CP437. 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.
      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).

    - #### newPDF417

          public static BarCode newPDF417(byte[] value,
                                          float xunit,
                                          int securitylevel,
                                          int columns)

      Create a new PDF417 BarCode from binary data. 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.
      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(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,
                                            String postcode,
                                            int country,
                                            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,
                                            String postcode,
                                            String country,
                                            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(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(String value,
                                          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(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(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(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 Ausprä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(String mailingnumber,
                                                      int issuer,
                                                      int product,
                                                      int postcode,
                                                      String clientjob,
                                                      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, Produktschlü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(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(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

    - #### 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(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 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 algorithms can be resized, and for some (eg MaxiCode, the various postal bar codes) 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()`
      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()`

    - #### 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, 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.

    - #### 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 BufferedImage getBufferedImage(double scale,
                                                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

Copyright © 2001-2015 Big Faceless Organization