Class BarcodeQRCode

java.lang.Object
com.itextpdf.barcodes.Barcode2D
com.itextpdf.barcodes.BarcodeQRCode

public class BarcodeQRCode extends Barcode2D
A QRCode implementation based on the zxing code.
  • Constructor Details

    • BarcodeQRCode

      public BarcodeQRCode (String code, Map<EncodeHintType,Object> hints)
      Creates the QR barcode.
      Parameters:
      code - the text to be encoded
      hints - barcode hints. See #setHints for description.
    • BarcodeQRCode

      public BarcodeQRCode (String content)
      Creates the QR barcode with default error correction level (ErrorCorrectionLevel.L) and default character set (ISO-8859-1).
      Parameters:
      content - the text to be encoded
    • BarcodeQRCode

      public BarcodeQRCode()
  • Method Details

    • getCode

      public String getCode()
      Gets the current data.
      Returns:
      the encoded data
    • setCode

      public void setCode (String code)
      Sets the data to be encoded by the barcode. If not specified in hints otherwise, the character set should be ISO-8859-1.
      Parameters:
      code - The data to encode
    • getHints

      public Map<EncodeHintType,Object> getHints()
      Returns:
      modifiers to change the way the barcode is created.
    • setHints

      public void setHints (Map<EncodeHintType,Object> hints)
      Parameters:
      hints - modifiers to change the way the barcode is created. They can be EncodeHintType.ERROR_CORRECTION and EncodeHintType.CHARACTER_SET. For EncodeHintType.ERROR_CORRECTION the values can be ErrorCorrectionLevel.L, M, Q, H. For EncodeHintType.CHARACTER_SET the values are strings and can be Cp437, Shift_JIS and ISO-8859-1 to ISO-8859-16. You can also use UTF-8, but correct behaviour is not guaranteed as Unicode is not supported in QRCodes. The default value is ISO-8859-1.
    • regenerate

      public void regenerate()
      Regenerates barcode after changes in hints or code.
    • getBarcodeSize

      public Rectangle getBarcodeSize()
      Gets the size of the barcode grid
      Specified by:
      getBarcodeSize in class Barcode2D
      Returns:
      the size the barcode occupies.
    • getBarcodeSize

      public Rectangle getBarcodeSize (float moduleSize)
      Gets the barcode size
      Parameters:
      moduleSize - The module size
      Returns:
      The size of the barcode
    • placeBarcode

      public Rectangle placeBarcode (PdfCanvas canvas, Color foreground)
      Description copied from class: Barcode2D
      Places the barcode in a PdfCanvas. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.
      Specified by:
      placeBarcode in class Barcode2D
      Parameters:
      canvas - the PdfCanvas where the barcode will be placed
      foreground - the foreground color. It can be null
      Returns:
      the dimensions the barcode occupies
    • placeBarcode

      public Rectangle placeBarcode (PdfCanvas canvas, Color foreground, float moduleSide)
      * Places the barcode in a PdfCanvas. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.
      Parameters:
      canvas - the PdfCanvas where the barcode will be placed
      foreground - the foreground color. It can be null
      moduleSide - the size of the square grid cell
      Returns:
      the dimensions the barcode occupies
    • createFormXObject

      public PdfFormXObject createFormXObject (Color foreground, PdfDocument document)
      Creates a PdfFormXObject with the barcode.
      Specified by:
      createFormXObject in class Barcode2D
      Parameters:
      foreground - the color of the pixels. It can be null
      document - The document
      Returns:
      the XObject.
    • createFormXObject

      public PdfFormXObject createFormXObject (Color foreground, float moduleSize, PdfDocument document)
      Creates a PdfFormXObject with the barcode.
      Parameters:
      foreground - The color of the pixels. It can be null
      moduleSize - The size of the pixels.
      document - The document
      Returns:
      the XObject.
    • createAwtImage

      public Image createAwtImage (Color foreground, Color background)
      Creates a java.awt.Image.
      Parameters:
      foreground - the color of the bars
      background - the color of the background
      Returns:
      the image