Class DataMatrix

java.lang.Object
com.pdfjet.datamatrix.DataMatrix
All Implemented Interfaces:
Drawable

public final class DataMatrix extends Object implements Drawable
Used to create 2D Data Matrix barcodes: ECC 200 symbols as specified in ISO/IEC 16022. The text is encoded as UTF-8 in the smallest symbol that holds it. Please see Example_37.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Rectangular symbols, from 8x18 to 16x48 modules.
    static final int
    Square symbols, from 10x10 to 144x144 modules.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a square Data Matrix barcode.
    DataMatrix(String str, int shape)
    Creates a Data Matrix barcode.
  • Method Summary

    Modifier and Type
    Method
    Description
    float[]
    drawOn(Page page)
    Draws this barcode on the specified page.
    static DataMatrix
    Creates a square GS1 DataMatrix barcode, as medicines, medical devices and, more and more, retail goods carry.
    static DataMatrix
    fromGS1(String str, int shape)
    Creates a GS1 DataMatrix barcode.
    boolean[][]
    Returns the modules of this barcode, by row and column; true is dark.
    setAltDescription(String altDescription)
    Sets what the barcode says for a screen reader: a tagged document, PDF/UA or a PDF/A of level A, then has the barcode as a figure of that description.
    setLocation(float x, float y)
    Sets the location where this barcode will be drawn on the page.
    setModuleColor(int color)
    Sets the color of the barcode.
    setModuleLength(float moduleLength)
    Sets the module length of this barcode.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SQUARE

      public static final int SQUARE
      Square symbols, from 10x10 to 144x144 modules.
      See Also:
    • RECTANGLE

      public static final int RECTANGLE
      Rectangular symbols, from 8x18 to 16x48 modules. Data that does not fit in a rectangular symbol gets a square symbol.
      See Also:
  • Constructor Details

    • DataMatrix

      public DataMatrix(String str)
      Creates a square Data Matrix barcode.
      Parameters:
      str - the text to encode.
    • DataMatrix

      public DataMatrix(String str, int shape)
      Creates a Data Matrix barcode.
      Parameters:
      str - the text to encode.
      shape - DataMatrix.SQUARE or DataMatrix.RECTANGLE.
      Throws:
      IllegalArgumentException - if the text does not fit in the largest symbol.
  • Method Details

    • fromGS1

      public static DataMatrix fromGS1(String str)
      Creates a square GS1 DataMatrix barcode, as medicines, medical devices and, more and more, retail goods carry. The data is written as people read it: each Application Identifier in parentheses and its data after it, such as "(01)09506000134352(17)261231(10)ABC123". The symbol starts with FNC1, which says it is GS1, and a field of no set length is ended with GS when another follows.
      Parameters:
      str - the GS1 data.
      Returns:
      the barcode.
      Throws:
      IllegalArgumentException - if the data is not GS1: an Application Identifier that is not two to four digits, or with no data; a character GS1 does not allow, a parenthesis among them; data longer than 90 characters; data of a field of set length, such as the GTIN of (01) or the date of (17), that is not that many digits; or a wrong check digit of an SSCC (00), a GTIN (01) or (02), or a GLN (410) to (417). Also if the data does not fit in the largest symbol.
    • fromGS1

      public static DataMatrix fromGS1(String str, int shape)
      Creates a GS1 DataMatrix barcode. See fromGS1(String).
      Parameters:
      str - the GS1 data.
      shape - DataMatrix.SQUARE or DataMatrix.RECTANGLE.
      Returns:
      the barcode.
      Throws:
      IllegalArgumentException - if the data is not GS1, or does not fit in the largest symbol.
    • setLocation

      public DataMatrix setLocation(float x, float y)
      Sets the location where this barcode will be drawn on the page.
      Specified by:
      setLocation in interface Drawable
      Parameters:
      x - the x coordinate of the top left corner of the barcode.
      y - the y coordinate of the top left corner of the barcode.
      Returns:
      this DataMatrix object.
    • setModuleLength

      public DataMatrix setModuleLength(float moduleLength)
      Sets the module length of this barcode. The default value is 2.0f. Leave a margin of at least one module around the barcode.
      Parameters:
      moduleLength - the module length.
      Returns:
      this DataMatrix object.
    • setModuleColor

      public DataMatrix setModuleColor(int color)
      Sets the color of the barcode.
      Parameters:
      color - the color as a 0xRRGGBB value.
      Returns:
      this DataMatrix object.
    • getModules

      public boolean[][] getModules()
      Returns the modules of this barcode, by row and column; true is dark.
      Returns:
      the modules.
    • setAltDescription

      public DataMatrix setAltDescription(String altDescription)
      Sets what the barcode says for a screen reader: a tagged document, PDF/UA or a PDF/A of level A, then has the barcode as a figure of that description. Without one, its modules are decoration, which a screen reader skips.
      Parameters:
      altDescription - the description.
      Returns:
      this DataMatrix object.
    • drawOn

      public float[] drawOn(Page page) throws Exception
      Draws this barcode on the specified page. With no page nothing is drawn. The brush of the page is as it was after it.
      Specified by:
      drawOn in interface Drawable
      Parameters:
      page - the page to draw on.
      Returns:
      the x and y coordinates of the bottom right corner of this barcode.
      Throws:
      Exception - if an input or output exception occurred.