Package com.itextpdf.barcodes
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.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ByteMatrix
bm
(package private) java.lang.String
code
(package private) java.util.Map<EncodeHintType,java.lang.Object>
hints
modifiers to change the way the barcode is create.-
Fields inherited from class com.itextpdf.barcodes.Barcode2D
DEFAULT_MODULE_SIZE
-
-
Constructor Summary
Constructors Constructor Description BarcodeQRCode()
Creates an instance of theBarcodeQRCode
class.BarcodeQRCode(java.lang.String content)
Creates the QR barcode with default error correction level (ErrorCorrectionLevel.L) and default character set (ISO-8859-1).BarcodeQRCode(java.lang.String code, java.util.Map<EncodeHintType,java.lang.Object> hints)
Creates the QR barcode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Image
createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
.PdfFormXObject
createFormXObject(Color foreground, float moduleSize, PdfDocument document)
Creates a PdfFormXObject with the barcode.PdfFormXObject
createFormXObject(Color foreground, PdfDocument document)
Creates a PdfFormXObject with the barcode.Rectangle
getBarcodeSize()
Gets the size of the barcode gridRectangle
getBarcodeSize(float moduleSize)
Gets the barcode sizeprivate byte[]
getBitMatrix()
java.lang.String
getCode()
Gets the current data.java.util.Map<EncodeHintType,java.lang.Object>
getHints()
Rectangle
placeBarcode(PdfCanvas canvas, Color foreground)
Places the barcode in aPdfCanvas
.Rectangle
placeBarcode(PdfCanvas canvas, Color foreground, float moduleSide)
* Places the barcode in aPdfCanvas
.void
regenerate()
Regenerates barcode after changes in hints or code.void
setCode(java.lang.String code)
Sets the data to be encoded by the barcode.void
setHints(java.util.Map<EncodeHintType,java.lang.Object> hints)
-
Methods inherited from class com.itextpdf.barcodes.Barcode2D
createFormXObject
-
-
-
-
Field Detail
-
bm
ByteMatrix bm
-
hints
java.util.Map<EncodeHintType,java.lang.Object> hints
modifiers to change the way the barcode is create.
-
code
java.lang.String code
-
-
Constructor Detail
-
BarcodeQRCode
public BarcodeQRCode(java.lang.String code, java.util.Map<EncodeHintType,java.lang.Object> hints)
Creates the QR barcode.- Parameters:
code
- the text to be encodedhints
- barcode hints. See #setHints for description.
-
BarcodeQRCode
public BarcodeQRCode(java.lang.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()
Creates an instance of theBarcodeQRCode
class.
-
-
Method Detail
-
getCode
public java.lang.String getCode()
Gets the current data.- Returns:
- the encoded data
-
setCode
public void setCode(java.lang.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 java.util.Map<EncodeHintType,java.lang.Object> getHints()
- Returns:
- modifiers to change the way the barcode is created.
-
setHints
public void setHints(java.util.Map<EncodeHintType,java.lang.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 classBarcode2D
- 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 aPdfCanvas
. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.- Specified by:
placeBarcode
in classBarcode2D
- Parameters:
canvas
- thePdfCanvas
where the barcode will be placedforeground
- the foreground color. It can benull
- Returns:
- the dimensions the barcode occupies
-
placeBarcode
public Rectangle placeBarcode(PdfCanvas canvas, Color foreground, float moduleSide)
* Places the barcode in aPdfCanvas
. The barcode is always placed at coordinates (0, 0). Use the translation matrix to move it elsewhere.- Parameters:
canvas
- thePdfCanvas
where the barcode will be placedforeground
- the foreground color. It can benull
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 classBarcode2D
- Parameters:
foreground
- the color of the pixels. It can benull
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 benull
moduleSize
- The size of the pixels.document
- The document- Returns:
- the XObject.
-
createAwtImage
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background)
Creates ajava.awt.Image
.- Parameters:
foreground
- the color of the barsbackground
- the color of the background- Returns:
- the image
-
getBitMatrix
private byte[] getBitMatrix()
-
-