PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
QR Code with a Text Caption
See more QR Code Examples
Demonstrates printing a line of text under a QR code, such as the order number or the address the code holds, so that a person can read it too. render.text turns the caption on and gives its value, which is printable ASCII and is drawn in a built-in font that needs no font files. The caption can go above or below the symbol, be aligned left, center or right, and be scaled.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
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.
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/order/12345")
loo_Json.UpdateInt("render.moduleSize",6)
// The caption. It need not be the same as the text in the QR code.
loo_Json.UpdateBool("render.text.enabled",1)
loo_Json.UpdateString("render.text.value","ORDER 12345")
// position is "below" (the default) or "above". alignment is "center" (the default), "left" or "right".
loo_Json.UpdateString("render.text.position","below")
// Each dot of the caption's font is drawn this many pixels wide.
loo_Json.UpdateInt("render.text.scale",3)
loo_Json.UpdateString("output.path","qa_output/qr_caption.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_Json
destroy loo_Fmt
destroy loo_JsonOut
return
end if
Write-Debug "caption: " + loo_JsonOut.StringOf("measurements[0].text")
Write-Debug "caption scale: " + string(loo_JsonOut.IntOf("measurements[0].textScale"))
Write-Debug "height added for the caption: " + string(loo_JsonOut.IntOf("measurements[0].textBandPx")) + " pixels"
Write-Debug "image: " + string(loo_JsonOut.IntOf("measurements[0].canvasWidth")) + " x " + string(loo_JsonOut.IntOf("measurements[0].canvasHeight")) + " pixels"
// The image written to qa_output/qr_caption.png:
//
// Sample output:
// caption: ORDER 12345
// caption scale: 3
// height added for the caption: 21 pixels
// image: 222 x 243 pixels
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut