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

Embed a QR Code in HTML as a Data URI

See more QR Code Examples

Demonstrates putting a QR code directly into an HTML page or HTML email with no separate image file. The base64 PNG returned by QrCode becomes the src of an img tag as a data URI, which is the MIME type from outputs[0].mimeType followed by the base64 from outputs[0].base64.

Chilkat PowerBuilder Downloads

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

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.UpdateInt("render.moduleSize",5)

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

//  A data URI has the form  data:<MIME type>;base64,<base64 data>
loo_SbHtml = create oleobject
li_rc = loo_SbHtml.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbHtml.Append("<html><body><p>Scan to visit chilkatsoft.com</p><img alt=~"QR code~" width=~"")
loo_SbHtml.AppendInt(loo_JsonOut.IntOf("outputs[0].width"))
loo_SbHtml.Append("~" height=~"")
loo_SbHtml.AppendInt(loo_JsonOut.IntOf("outputs[0].height"))
loo_SbHtml.Append("~" src=~"data:")
loo_SbHtml.Append(loo_JsonOut.StringOf("outputs[0].mimeType"))
loo_SbHtml.Append(";base64,")
loo_SbHtml.Append(loo_JsonOut.StringOf("outputs[0].base64"))
loo_SbHtml.Append("~"></body></html>")

li_Success = loo_SbHtml.WriteFile("qa_output/qr_page.html","utf-8",0)
if li_Success = 0 then
    Write-Debug loo_SbHtml.LastErrorText
    destroy loo_Json
    destroy loo_Fmt
    destroy loo_JsonOut
    destroy loo_SbHtml
    return
end if

Write-Debug "image: " + string(loo_JsonOut.IntOf("outputs[0].width")) + " x " + string(loo_JsonOut.IntOf("outputs[0].height")) + " pixels"
Write-Debug "HTML length: " + string(loo_SbHtml.Length)

//  The page, as a browser shows it:

//  image

//  Sample output:

//  image: 185 x 185 pixels
//  HTML length: 1211


destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
destroy loo_SbHtml