PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
QR Code with a Physical Size in Millimeters at a Printer DPI
See more QR Code Examples
Demonstrates sizing a QR code for print. With render.units set to mm (or in, or pt) the module size is a physical length, and render.dpi says how many pixels the printer or the image has per inch. A module is always a whole number of pixels, because modules of uneven width scan badly, so the size asked for is rounded to the nearest pixel and the response reports the size actually used. The PNG records the dpi, so software that honors it prints the image at that physical size.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/")
// Modules of 0.5 mm, for a 300 dpi printer.
loo_Json.UpdateString("render.units","mm")
loo_Json.UpdateNumber("render.moduleSize","0.5")
loo_Json.UpdateInt("render.dpi",300)
loo_Json.UpdateString("output.path","qa_output/qr_300dpi.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
// 0.5 mm at 300 dpi is 5.9 pixels, so each module is drawn 6 pixels wide.
Write-Debug "requested module: " + loo_JsonOut.StringOf("measurements[0].requestedPitch") + " pixels"
Write-Debug "module drawn: " + string(loo_JsonOut.IntOf("measurements[0].pitch")) + " pixels = " + loo_JsonOut.StringOf("measurements[0].moduleSize") + " mm"
Write-Debug "size was rounded: " + string(loo_JsonOut.BoolOf("measurements[0].pitchAdjusted"))
Write-Debug "image: " + string(loo_JsonOut.IntOf("measurements[0].canvasWidth")) + " x " + string(loo_JsonOut.IntOf("measurements[0].canvasHeight")) + " pixels"
Write-Debug "printed size: " + loo_JsonOut.StringOf("measurements[0].physicalWidth") + " x " + loo_JsonOut.StringOf("measurements[0].physicalHeight") + " mm"
// The image. A web page shows it pixel for pixel. Printed at 300 dpi it is 18.8 mm wide:
//
// When the exact size matters more than getting an image, requireExactPitch makes a size
// that is not a whole number of pixels a failure (noFit) instead of rounding it.
loo_Json.UpdateBool("render.requireExactPitch",1)
li_Success = loo_Fmt.QrCode("generate",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug "requireExactPitch: " + loo_JsonOut.StringOf("errors[0].code") + " (" + loo_JsonOut.StringOf("errors[0].message") + ")"
end if
// Sample output:
// requested module: 5.905512 pixels
// module drawn: 6 pixels = 0.508 mm
// size was rounded: True
// image: 222 x 222 pixels
// printed size: 18.796 x 18.796 mm
// requireExactPitch: noFit (the symbol does not fit the render constraints: pitchAdjusted)
destroy loo_Json
destroy loo_Fmt
destroy loo_JsonOut