Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.7.0+

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 Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.StringBuilder,
  Chilkat.Formats,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  json: TJsonObject;
  fmt: TFormats;
  jsonOut: TJsonObject;
  sbSvg: TStringBuilder;

begin
  success := False;

  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  json := TJsonObject.Create;
  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 := TFormats.Create;
  jsonOut := TJsonObject.Create;
  success := fmt.QrCode('generate',json,jsonOut);
  if (success = False) then
    begin
      WriteLn(fmt.LastErrorText);
      Exit;
    end;

  sbSvg := TStringBuilder.Create;
  jsonOut.StringOfSb('outputs[0].text',sbSvg);

  WriteLn('MIME type: ' + jsonOut.StringOf('outputs[0].mimeType'));
  WriteLn('size: ' + jsonOut.IntOf('outputs[0].width') + ' x ' + jsonOut.IntOf('outputs[0].height') + ' ' + jsonOut.StringOf('outputs[0].units'));
  WriteLn('SVG length: ' + 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',False);
  if (success = False) then
    begin
      WriteLn(sbSvg.LastErrorText);
      Exit;
    end;

  //  The SVG:

  //  image

  //  Sample output:

  //  MIME type: image/svg+xml
  //  size: 148 x 148 px
  //  SVG length: 12500 characters


  json.Free;
  fmt.Free;
  jsonOut.Free;
  sbSvg.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.