Delphi ActiveX Requires Chilkat v11.7.0+
Delphi ActiveX
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 ActiveX Downloads
var
success: Integer;
json: TChilkatJsonObject;
fmt: TChilkatFormats;
jsonOut: TChilkatJsonObject;
sbSvg: TChilkatStringBuilder;
begin
success := 0;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
json := TChilkatJsonObject.Create(Self);
json.UpdateString('payload.text','https://www.chilkatsoft.com/');
json.UpdateString('output.format','svg');
// An SVG is text, so it can be returned as text rather than as base64.
json.UpdateString('output.return','text');
fmt := TChilkatFormats.Create(Self);
jsonOut := TChilkatJsonObject.Create(Self);
success := fmt.QrCode('generate',json.ControlInterface,jsonOut.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(fmt.LastErrorText);
Exit;
end;
sbSvg := TChilkatStringBuilder.Create(Self);
jsonOut.StringOfSb('outputs[0].text',sbSvg.ControlInterface);
Memo1.Lines.Add('MIME type: ' + jsonOut.StringOf('outputs[0].mimeType'));
Memo1.Lines.Add('size: ' + IntToStr(jsonOut.IntOf('outputs[0].width')) + ' x ' + IntToStr(jsonOut.IntOf('outputs[0].height')) + ' ' + jsonOut.StringOf('outputs[0].units'));
Memo1.Lines.Add('SVG length: ' + IntToStr(sbSvg.Length) + ' characters');
// The SVG is a complete document that can be saved, or placed inline in an HTML page.
success := sbSvg.WriteFile('qa_output/qr_chilkat.svg','utf-8',0);
if (success = 0) then
begin
Memo1.Lines.Add(sbSvg.LastErrorText);
Exit;
end;
// The SVG:
//
// Sample output:
// MIME type: image/svg+xml
// size: 148 x 148 px
// SVG length: 12500 characters