How to print a QR code on SSRS report

 Hello AX World,


Generating a QR code to an SSRS report is easy.

There is a standard library in ApplicationSuite for QR code generation.

using Microsoft.Dynamics.ApplicationSuite.QRCode;

One important note: if you are working with 8.1 you will need to apply the update KB 4494407 as the library has a bug. 

Create QR Code

1. QR code generator creates an image out of the text so you need an image (container) type field on your report data source table. 

2. Once you have the field, the generation can be performed with a one-liner.

reportTableTmp.QRCode = new EFDocQRCode_BR().generateQRCode("Hello world");

If you don't want to use this class, you can copy the code from inside and use that. Don't forget to use the library.

using Microsoft.Dynamics.ApplicationSuite.QRCode;

try
{
    Encoder qrCodeEncoder = new Encoder();
    using(System.Drawing.Bitmap bm = qrCodeEncoder.Encode("Hello world"))
    {
        using (var stream = new System.IO.MemoryStream())
        {
            bm.Save(stream, System.Drawing.Imaging.ImageFormat::Png);
            reportTableTmp.QRCode Binary::constructFromMemoryStream(stream).getContainer();
        }
    }
}
catch (Exception::CLRError)
{
    throw error(CLRInterop::getLastException().ToString());
}


3. The last step is to add an image to an SSRS report.
I recommend setting image's Sizing property to Fit proportional as the generated image is rather small. 


Here you go, you have a QR code.

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++