Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
Generate a QR Code as SVG
See more QR Code Examples
Demonstrates SVG output. An SVG is a vector image, so it stays sharp at any size, which suits print and responsive web pages. Setting output.format to svg and output.return to text returns the SVG document as a string in outputs[0].text. The SVG can also be written straight to a file with output.path, the same as a PNG.Chilkat Delphi DLL Downloads
var
success: Boolean;
json: HCkJsonObject;
fmt: HCkFormats;
jsonOut: HCkJsonObject;
sbSvg: HCkStringBuilder;
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/');
CkJsonObject_UpdateString(json,'output.format','svg');
// An SVG is text, so it can be returned as text rather than as base64.
CkJsonObject_UpdateString(json,'output.return','text');
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;
sbSvg := CkStringBuilder_Create();
CkJsonObject_StringOfSb(jsonOut,'outputs[0].text',sbSvg);
Memo1.Lines.Add('MIME type: ' + CkJsonObject__stringOf(jsonOut,'outputs[0].mimeType'));
Memo1.Lines.Add('size: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].width')) + ' x ' + IntToStr(CkJsonObject_IntOf(jsonOut,'outputs[0].height')) + ' ' + CkJsonObject__stringOf(jsonOut,'outputs[0].units'));
Memo1.Lines.Add('SVG length: ' + IntToStr(CkStringBuilder_getLength(sbSvg)) + ' characters');
// The SVG is a complete document that can be saved, or placed inline in an HTML page.
success := CkStringBuilder_WriteFile(sbSvg,'qa_output/qr_chilkat.svg','utf-8',False);
if (success = False) then
begin
Memo1.Lines.Add(CkStringBuilder__lastErrorText(sbSvg));
Exit;
end;
// The SVG:
//
// Sample output:
// MIME type: image/svg+xml
// size: 148 x 148 px
// SVG length: 12500 characters
CkJsonObject_Dispose(json);
CkFormats_Dispose(fmt);
CkJsonObject_Dispose(jsonOut);
CkStringBuilder_Dispose(sbSvg);