THPDFPage.DrawQRCode Method
Encodes Data as an ISO/IEC 18004 QR Code (Model 2) and paints it on the page as a grid of filled squares. The encoder picks the smallest version (1 to 40) that holds the data at the requested error correction level, chooses numeric, alphanumeric or byte mode automatically and selects the mask with the lowest penalty score
Declaration
function DrawQRCode(const Data: AnsiString; X, Y: Single; ModuleSize: Single= 2; ECLevel: THPDFQRECLevel= qrM; Color: TColor= clBlack): Integer;
Unit
HPDFDoc
Parameters
| Name | Purpose |
|---|---|
Data | Bytes to encode. Digits only use numeric mode, text limited to the upper-case alphanumeric set (0-9 A-Z, space and $%*+-./:) uses alphanumeric mode, and anything else, including lower-case letters, is stored byte for byte. Pass UTF-8 bytes for non-ASCII text |
X | Left edge of the symbol in page coordinates |
Y | Top edge of the symbol in page coordinates |
ModuleSize | Side length of one module, in drawing units (points at the default Resolution of 72). Must be greater than zero |
ECLevel | Error correction level: qrL (about 7 % recovery), qrM (15 %), qrQ (25 %) or qrH (30 %). Higher levels need a larger symbol for the same data |
Color | Fill color of the dark modules. Light modules are not painted, so place the symbol on a light background |
Return value
The number of modules along one side of the symbol (21 for version 1 up to 177 for version 40), so the symbol covers Result * ModuleSize drawing units in each direction. Returns 0 and draws nothing when Data is empty, ModuleSize is not positive or the data does not fit a version 40 symbol at the chosen level
Usage notes
- The quiet zone is not drawn. Keep at least four modules of empty space around the symbol so that scanners can find it
- The page fill color is changed to
Color; set it again before painting other filled shapes - Page-level changes affect subsequent operators on the same page; save and restore graphics state when a temporary setting should not leak