PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
QR Code with Non-English Text (UTF-8 and ECI)
See more QR Code Examples
Demonstrates text outside ASCII. QrCode always stores text as UTF-8 bytes, which is what phones expect. A QR code can also say so explicitly with an ECI header: setting encoding.eci to 26 declares the bytes to be UTF-8, for readers that would otherwise assume another character set. The header costs a little space, and a few older readers do not understand it, so it is off by default.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_SbText
oleobject loo_Json
oleobject loo_Fmt
oleobject loo_JsonOut
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The text is "Gruesse aus Muenchen" written with u-umlaut and sharp s. It is given here with
// JSON escapes only so that this source is plain ASCII. Decode turns the escapes into characters.
loo_SbText = create oleobject
li_rc = loo_SbText.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
destroy loo_SbText
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_SbText.Append("Gr\u00fc\u00dfe aus M\u00fcnchen")
loo_SbText.Decode("json","utf-8")
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateSb("payload.text",loo_SbText)
loo_Json.UpdateString("output.path","qa_output/qr_utf8.png")
loo_Json.UpdateBool("output.overwrite",1)
loo_Json.UpdateString("output.return","none")
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_SbText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
return
end if
// 17 characters, three of which take two bytes in UTF-8.
Write-Debug "characters: " + string(loo_SbText.Length)
Write-Debug "bytes encoded: " + string(loo_JsonOut.IntOf("symbols[0].payloadBytes"))
Write-Debug "ECI header: " + string(loo_JsonOut.HasMember("symbols[0].selectedEncoding.eci"))
// Without an ECI header (qa_output/qr_utf8.png):
//
// The same text with an ECI header declaring UTF-8.
loo_Json.UpdateInt("encoding.eci",26)
loo_Json.UpdateString("output.path","qa_output/qr_utf8_eci.png")
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Fmt.LastErrorText
destroy loo_SbText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut
return
end if
Write-Debug "with encoding.eci = 26, ECI header: " + string(loo_JsonOut.HasMember("symbols[0].selectedEncoding.eci")) + ", value " + string(loo_JsonOut.IntOf("symbols[0].selectedEncoding.eci"))
// With the ECI header (qa_output/qr_utf8_eci.png). Both scan as the same text:
//
// Sample output:
// characters: 17
// bytes encoded: 20
// ECI header: False
// with encoding.eci = 26, ECI header: True, value 26
destroy loo_SbText
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut