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 chooses the smallest version (1 to 40) capable of holding the data at the requested error correction level, selects numeric, alphanumeric or byte mode of its own accord, and settles on 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 | The bytes to encode. Digits alone use numeric mode; text confined to the upper-case alphanumeric set (0-9 A-Z, space and $%*+-./:) uses alphanumeric mode; anything else — lower-case letters included — is stored byte for byte. Pass UTF-8 bytes for non-ASCII text |
X | Left-hand edge of the symbol in page coordinates |
Y | Top edge of the symbol in page coordinates |
ModuleSize | Side length of a single module, in drawing units (points when Resolution stays at its default of 72); must be greater than zero |
ECLevel | Error correction level: qrL (roughly 7 % recovery), qrM (15 %), qrQ (25 %) or qrH (30 %). Higher levels call for a larger symbol to carry the same data |
Color | Fill colour of the dark modules. Light modules are not painted, so site the symbol on a light background |
Return value
The number of modules along one side of the symbol (21 for version 1 through 177 for version 40), so the symbol spans Result * ModuleSize drawing units in each direction. Gives 0 and draws nothing when Data is empty, ModuleSize is not positive, or the data will not fit a version 40 symbol at the chosen level
Usage notes
- The quiet zone is not drawn; leave at least four modules of clear space around the symbol so scanners can locate it
- The page fill colour is set to
Color; restore it before painting any 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