Hi everyone,
I’m generating a QR code in Business Central using a Base64-encoded TLV string.
When I save the Base64 value in a field (Text type) it looks fine, for example:
ARBDUk9OVVMgVVNBLCBJbmMuAg8zOTk5OTk5OTk5MDAwMDMDEzIwMjUtMTAtMDZUMTI6MzQ6MjYEAzExNQUCMTUGLGlPbW1jeXFLVDNacUtKdmtHeXJ5TDJJMjRoZ0xQTkE5YTN2Vmo1NnNlYnM9B2BNRVVDSVFEZ1VZbkwvSXU3VXRGZmVYU3grd1c1TWVCd3VZWmNYMThJcTQwUUJ4UmJYZ0lnRW1DcHI4SjlmWEJLWXhFT0ZRQ2kyL1dOa3ZqaHdmckNreGJOTm0za3hCOD0IWDBWMBAGByqGSM49AgEGBSuBBAAKA0IABEl0eQuQYGlPgM1c0f/9w7Qu7m+btzmGMFFWuJOMPhqitKtnFTfBDX12GScv+14ddfJqG5ITqkJDVc7NEhnq+c0=
But when the QR code is generated and printed, the encoded text in the QR includes extra white spaces, for example:
ARBDUk9OVVMgVVNBLCBJbmMuAg8zOTk5OTk5OTk5MDAwMDMDEzIwMjUtMTAtMDZUMTI6MzQ6MjYEAzExNQUCMTUGLGlPbW1jeXFLVDNacUtKdmtHeXJ5TDJJMjRoZ0xQTkE5YTN2Vmo1NnNlYnM9B2BNRVVDSVFEZ1VZbkwvSXU3VXRGZmVYU3grd1c1TWVCd3VZWmNYMThJcTQwUUJ4UmJYZ0lnRW1DcHI4SjlmWEJLWXhFT0ZRQ2kyL1dOa3ZqaHdmckNreGJOTm0za3hCOD0IWDBWMBAGByqGSM49AgEGBSuBBAAKA0IABEl0eQuQYGlPgM1c0f/9w7Qu7m btzmGMFFWuJOMPhqitKtnFTfBDX12GScv 14ddfJqG5ITqkJDVc7NEhnq c0=
As you can see, extra spaces appear randomly inside the Base64 text (e.g. after 7m
, after Scv
, etc.), which causes QR code verification to fail.How can I safely encode and render the QR without breaking the Base64 format
Hello,
The best way to avoid these issues entirely is to not send the Base64 string to the report at all. Instead, generate the QR code image directly in AL code and pass the image itself to the report via a BLOB
field.
This method bypasses any text formatting or wrapping issues because the report is only responsible for displaying a pre-rendered image.
Here is the workflow:
Generate QR Image in AL: o convert your TLV string directly into an image (e.g., a PNG byte array).
Store in a BLOB: Load this byte array into an OutStream
connected to a BLOB
field on a temporary table.
Add BLOB to Dataset: Add this BLOB
field to your report's dataset.
Display in Report Layout:
In your RDLC or Word layout, add an Image control.
Set the image's source to Database
.
Set its value to be the BLOB
field from your dataset.
Set the MIMEType
to image/png
(or whichever format you generated).
This approach is more reliable because the report layout engine is simply rendering a picture and doesn't get a chance to "fix" the long text string.