Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

How to generate QR CODE with Arabic characters

(0) ShareShare
ReportReport
Posted on by 3,085

Hello Experts,

I have generated the QR within the Sales Invoice report but the problem is while I am trying to generate the same with Arabic characters it wont appear.

Following are the code.

    Microsoft.Dynamics.QRCode.Encoder   qrCode;
    System.String                       netString;
    str                                 tempFileName;
    System.Drawing.Bitmap               netBitmap;
   
    FileIOPermission                    perm;
    BinData                             binData;
    container                           imageContainer;
    
    ;


    netString = _QRDataString;//"ahmed muhammad alam and mohammad el sayed are the best brothers in bakheet along with Mr. Kashif choudry";
    qrCode = new Microsoft.Dynamics.QRCode.Encoder();
    netBitmap = qrCode.Encode(netString); //encode the string as Bitmap can be used already

    tempFileName = qrCode.GetTempFile(netString); //to get the QR temporary file

    perm = new FileIOPermission(tempFileName,'r');
    perm.assert();
    binData = new binData();
    binData.loadFile(tempFileName);
    imageContainer = binData.getData(); //get the QR code image put inside container so can be stored inside database for storing or reporting purpose


    CodeAccessPermission::revertAssert();
    return binData.getData();

  • Javidcse Profile Picture
    Javidcse 15 on at
    RE: How to generate QR CODE with Arabic characters

    download MessagingToolkit dll and use below code.

    MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();

    System.Drawing.Bitmap  obj = new System.Drawing.Bitmap(encoder.Encode('CompnayName/اسم الشركة', System.Text.Encoding::get_UTF8()));

  • Javidcse Profile Picture
    Javidcse 15 on at
    RE: How to generate QR CODE with Arabic characters

    download and use MessagingToolkit dll. use below code

    MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();

    System.Drawing.Bitmap  obj = new System.Drawing.Bitmap(encoder.Encode('CompnayName/اسم الشركة', System.Text.Encoding::get_UTF8()));

  • Abdulaziz Albloshi Profile Picture
    Abdulaziz Albloshi 365 on at
    RE: How to generate QR CODE with Arabic characters

    You are welcome,

    please mark the answer to be verified for future. Community member love verified answers :)

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: How to generate QR CODE with Arabic characters

    Hi Abdul Aziz,

    Thank you so much for the suggestion and for the very quick response.. The second option, saving to memory stream worked like a charm.

  • Abdulaziz Albloshi Profile Picture
    Abdulaziz Albloshi 365 on at
    RE: How to generate QR CODE with Arabic characters

    In D365FO the DLL is available by standard. You just need to use it in your custom code. You can go to AOT>Reference> QRCoder  will be there.

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: How to generate QR CODE with Arabic characters

    Hi Aziz,

    Thank you for the Quick reply, i will go with the second idea i.e memorystream. will try and let you know .

    BTW my environment is D365. i hope that QrCoder.dll would work fine as expected i hav added as reference to my project as you suggested above.

  • Abdulaziz Albloshi Profile Picture
    Abdulaziz Albloshi 365 on at
    RE: How to generate QR CODE with Arabic characters

    Hi,

    Let me summarize my work here:

    *******D365FO*******

    You have to use below code

    System.Drawing.Bitmap result;

          System.String totalString;

          totalString="النص باللغة العربية ";

          QRCodeGenerator.ECCLevel eccLevel;

          QRCodeGenerator qrGenerator = new QRCodeGenerator();

          QRCodeData qrCodeData = qrGenerator.CreateQrCode(totalString, eccLevel);

          QRCode qrCode = new QRCode(qrCodeData);

          result = qrCode.GetGraphic(20);

    now result variable have your bitmap with QR and you want to have it as a image container.

    you can do 2 things.

    1. Either save it in temp path and reread it in BinaryData and convert binary data to image container (Cons: Sometimes user doesnt av permission on local folder and this method will fail)

    //save to file

    //open file on binarydata

    //get binarydata on image

    2. OR save it to MemoryStream and reread it with BinaryData

    imageContainer=Binary::constructFromMemoryStream(memStream).getContainer();

    use imageContainer in your report/form etc

    **************AX 2012***********

    There is an issue with D365FO QRCoder.dll so you cannot utilize that DLL directly in AX 2012

    1. You will need to create a C# project

    2. Reference QRCoder.dll from D365FO on your project

    3. use QRCoder to generate bitmap and return it

    4. After compliation take the DLL and reference it AX 2012

    5. Use the referenced DLL and get the bitmap ready

    6. save it to file and reread it in container OR use memorystream

    Similarly goes for AX 2009.

    I hope you got the idea behind it.

    Mark the answer verified if it helps.

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: How to generate QR CODE with Arabic characters

    Hi aziz,

    Can u assit or provide the code how you hav done.

    i hav tried the above approach. the result is in bitmap, i hav to store to container field in the report. can u assist me on this.

    My environmet is D365

  • Abdulaziz Albloshi Profile Picture
    Abdulaziz Albloshi 365 on at
    RE: How to generate QR CODE with Arabic characters

    I didn't try on AX2012, but surely there will be a way to do that.

  • Rani alnoor Profile Picture
    Rani alnoor 10 on at
    RE: How to generate QR CODE with Arabic characters

    Can I use it on ax2012?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans