Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
QR Code with a Text Caption
See more QR Code Examples
Demonstrates printing a line of text under a QR code, such as the order number or the address the code holds, so that a person can read it too. render.text turns the caption on and gives its value, which is printable ASCII and is drawn in a built-in font that needs no font files. The caption can go above or below the symbol, be aligned left, center or right, and be scaled.Chilkat Delphi DLL Downloads
var
success: Boolean;
json: HCkJsonObject;
fmt: HCkFormats;
jsonOut: HCkJsonObject;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'payload.text','https://www.chilkatsoft.com/order/12345');
CkJsonObject_UpdateInt(json,'render.moduleSize',6);
// The caption. It need not be the same as the text in the QR code.
CkJsonObject_UpdateBool(json,'render.text.enabled',True);
CkJsonObject_UpdateString(json,'render.text.value','ORDER 12345');
// position is "below" (the default) or "above". alignment is "center" (the default), "left" or "right".
CkJsonObject_UpdateString(json,'render.text.position','below');
// Each dot of the caption's font is drawn this many pixels wide.
CkJsonObject_UpdateInt(json,'render.text.scale',3);
CkJsonObject_UpdateString(json,'output.path','qa_output/qr_caption.png');
CkJsonObject_UpdateBool(json,'output.overwrite',True);
CkJsonObject_UpdateString(json,'output.return','none');
fmt := CkFormats_Create();
jsonOut := CkJsonObject_Create();
success := CkFormats_QrCode(fmt,'generate',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkFormats__lastErrorText(fmt));
Exit;
end;
Memo1.Lines.Add('caption: ' + CkJsonObject__stringOf(jsonOut,'measurements[0].text'));
Memo1.Lines.Add('caption scale: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'measurements[0].textScale')));
Memo1.Lines.Add('height added for the caption: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'measurements[0].textBandPx')) + ' pixels');
Memo1.Lines.Add('image: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'measurements[0].canvasWidth')) + ' x ' + IntToStr(CkJsonObject_IntOf(jsonOut,'measurements[0].canvasHeight'))
+ ' pixels');
// The image written to qa_output/qr_caption.png:
//
// Sample output:
// caption: ORDER 12345
// caption scale: 3
// height added for the caption: 21 pixels
// image: 222 x 243 pixels
CkJsonObject_Dispose(json);
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);