Sample code for 30+ languages & platforms
PowerBuilder 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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Json
oleobject loo_Fmt
oleobject loo_JsonOut
oleobject loo_SbSvg

li_Success = 0

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_Json
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Json.UpdateString("payload.text","https://www.chilkatsoft.com/")
loo_Json.UpdateString("output.format","svg")

//  An SVG is text, so it can be returned as text rather than as base64.
loo_Json.UpdateString("output.return","text")

loo_Fmt = create oleobject
li_rc = loo_Fmt.ConnectToNewObject("Chilkat.Formats")

loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
    Write-Debug loo_Fmt.LastErrorText
    destroy loo_Json
    destroy loo_Fmt
    destroy loo_JsonOut
    return
end if

loo_SbSvg = create oleobject
li_rc = loo_SbSvg.ConnectToNewObject("Chilkat.StringBuilder")

loo_JsonOut.StringOfSb("outputs[0].text",loo_SbSvg)

Write-Debug "MIME type: " + loo_JsonOut.StringOf("outputs[0].mimeType")
Write-Debug "size: " + string(loo_JsonOut.IntOf("outputs[0].width")) + " x " + string(loo_JsonOut.IntOf("outputs[0].height")) + " " + loo_JsonOut.StringOf("outputs[0].units")
Write-Debug "SVG length: " + string(loo_SbSvg.Length) + " characters"

//  The SVG is a complete document that can be saved, or placed inline in an HTML page.
li_Success = loo_SbSvg.WriteFile("qa_output/qr_chilkat.svg","utf-8",0)
if li_Success = 0 then
    Write-Debug loo_SbSvg.LastErrorText
    destroy loo_Json
    destroy loo_Fmt
    destroy loo_JsonOut
    destroy loo_SbSvg
    return
end if

//  The SVG:

//  image

//  Sample output:

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


destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_SbSvg