Published: 17.05.2021 | Edited: 17.05.2021 | Tags: 100daystooffload
Rotating QR codes in Zebra ZPL
I have discovered a strange behavior when instructing Zebra GK420t printer to make stickers containing some text and a QR code. Consider the following example:
Both QR codes are perfectly fine. They both can be printed with moth printers, including the trusty GK420t and they both can be decoded by the camera on the phone or the bar code scanner.
The difference is that the QR code on the right is rotated by 180 degrees. Rotation of the QR code should not be a problem, as the decoder can adjust for the orientation using position detection patterns. This is how a QR code is designed, to convey the same information no matter which angle it is viewed from.
ZPL instructions for a QR
However, using Zebra Designer 3 Essentials, the code generated for the left one looks like this:
^FT100,100 ^BQN,2,6 ^FH\^FDLA,https://peterbabic.dev^FS
While the one on the right creates a completely different output:
^FO100,100 ^GFA,03840,03840,00020,:Z64: eJztljEWgzAMQ82UY+SmkNw0x8gU11JoC+916BJNeODlfRZjyQpmTz31u7Zuu+Xa7fC29exRXcQ2HNoRuOeCTjQsj/js5HhGU+5Vw7zFcVh2vFQyr5yBpWZCNq2FjlKoPWevYAAdXuPz67XV7OwFXWR+/We9VrPM2c8WKHtXMHg8heyx0Ib1evt+OYttdg8cM4iGpuYCBmunNgNspEYdFIwuj/FzszGMaEfEdjtjrPIsYt52Tr2eh0Y9ljNECIMkNC8zxjTMYO0ZYIM3xqFiKLpst1stZbyQQ+1cL3mqYPR4YXoN+9wVAobbuPIHBO2cuaZijDE9K+FxGE3JzN7/mHbTYzGj14rNxbr6by2zp/6uF7Naq7A=:26A4
The codes are almost identical, why such a difference in the code?
Printing graphic fields
The problem is in the features the actual printer supports. This particular printer supports ZPL instruction
^BQ for the QR code bar code. The instruction however accepts no input that describes it's rotation.
Because of no way to tell the printer how should the QR code be rotated, the software has to first encode the rotated code into the
^GF instruction for the graphic field. This way, the printer can still print it.
Problems with variable data
In order to encode variable data in the QR code, which is most of the time the stickers are printed in the industrial environment, encoding details such as product model, time and date, and maybe even an operator ID, we have to be able to modify it's instruction on the fly.
Modifying the data is simple in the case of
^BQ, as the data are stored in the plain text. It however becomes increasingly difficult to do the same with the rotated QR code, as the data there have to be first converted to the gprahical representation of the QR code, then rotated and then encoded in what is presumably a Base64 encoding.
Such would be a routine, which I could not find a straightforward documentation for. Even if it was readily available, it would be required to port it to the local environment where the printer is connected to, for instance the PLC.
Most of the modern printers use Ethernet connection, which is superior for more complicated designs, but GK420t does not. It uses a serial connection, implying a rather low-level controller. Unless absolutely unavoidable, printing rotated QR codes with variable data should be avoided with printers of this family.
This is a 68th post of #100daystooffload.