Pages

Tuesday, January 27, 2015

Create QR codes from AX 2012 R3 CU8

It seems like the Brazilian authorities are very modern in their approach to how you report to and communicate with them. I have found several neat things in AX from the Brazil specific features.

This time I stumbled over an assembly called QRCode and I thought I should look into what that was used for. It turns out you can create QR codes from AX pretty easy. Here is an example:
static void JobCreateQRCode(Args _args)
{
    Image           image;
    container       imageContainer;
    str             url;
    EFDocQRCode_BR  qrCode;  
    
    // The url to create the QR code. Could also for example be an e-mail address
    url = 'http://www.agermark.com';
    
    // Create an instance of the QR code class
    qrCode = new EFDocQRCode_BR();
    
    // Generate a QR code for the URL and save the result to a container
    imageContainer = qrCode.generateQRCode(url);
    
    // Use AX's good old Image class to load the image from the container
    // and save it as a file
    image = new Image();
    image.setData(imageContainer);
    
    image.saveImage("F:\QrCode.jpg", ImageSaveType::JPG);
}
You can now open the file and see the resulting QR code.

It links to www.agermark.com. Which leads me to the thing I really don't understand about QR codes. For security reasons we are always told not to click an URL that doesn't seem familiar. But scanning QR codes having absolute no idea about where they lead to is perfectly alright. Go figure.

5 comments:

kurthatlevik said...

Thanks Palle. Just a small additional comment. The EFDocQRCode_BR came with AX 2012 R3 CU 8 :-)

Palle Agermark said...

Thanks Kurt :-)

Mike Frank said...

This can be done in AX 2009 too. Even better? ;-)

static void JobCreateQRCode(Args _args)
{
str url;
Microsoft.Dynamics.QRCode.Encoder encoder;
System.Drawing.Bitmap bitmap;
// Here is the 2009 "drawback" ;-) semicolon is needed because URL is an EDT
;
// The url to create the QR code. Could also for example be an e-mail address
url = 'http://www.agermark.com';

// Create an instance of the QR code class
encoder = new Microsoft.Dynamics.QRCode.Encoder();

// This version creates a .NET bitmap
bitmap = encoder.Encode(url);

// you can save this in any format you like
bitmap.Save(@"C:\Temp\QrCode.jpg", System.Drawing.Imaging.ImageFormat::get_Jpeg());
}

Microsoft.Dynamics.QRCode.dll is available in Kernel version 5.0.1600.2967.
This is the recent published kernel build. Could be in an earlier kernel too.

Mike Frank said...

This can be done in AX 2009 too. Even better? ;-)

static void JobCreateQRCode(Args _args)
{
str url;
Microsoft.Dynamics.QRCode.Encoder encoder;
System.Drawing.Bitmap bitmap;
// Here is the 2009 "drawback" ;-) semicolon is needed because URL is an EDT
;
// The url to create the QR code. Could also for example be an e-mail address
url = 'http://www.agermark.com';

// Create an instance of the QR code class
encoder = new Microsoft.Dynamics.QRCode.Encoder();

// This version creates a .NET bitmap
bitmap = encoder.Encode(url);

// you can save this in any format you like
bitmap.Save(@"C:\Temp\QrCode.jpg", System.Drawing.Imaging.ImageFormat::get_Jpeg());
}

Microsoft.Dynamics.QRCode.dll is available in Kernel version 5.0.1600.2967.
This is the recent published kernel build. Could be in an earlier kernel too.

Palle Agermark said...

Nice one Mike :-)