procedure GetQRCode(QRCodeInput: Text) QRCodeImage: text var QRCoder: DotNet QRCodeGenerator; Base64QR: DotNet Base64QRCode; QRData: DotNet QRCodeData; QRCodeGenECCLevel: DotNet "QRCodeGenerator+ECCLevel"; QRCodeGenEciMode: DotNet "QRCodeGenerator+EciMode"; begin QRCoder := QRCoder.QRCodeGenerator(); QRData := QRCoder.CreateQrCode(QRCodeInput, QRCodeGenECCLevel.M, FALSE, FALSE, QRCodeGenEciMode.Default, -1); Base64QR := Base64QR.Base64QRCode(QRData); QRCodeImage := Base64QR.GetGraphic(3); end;
assembly("QRCoder") { type("QRCoder.QRCodeData"; QRCodeData) { } type("QRCoder.QRCodeGenerator"; "QRCodeGenerator") { } type("QRCoder.QRCodeGenerator+ECCLevel"; "QRCodeGenerator+ECCLevel") { } type("QRCoder.QRCodeGenerator+EciMode"; "QRCodeGenerator+EciMode") { } type("QRCoder.Base64QRCode"; "Base64QRCode") { } }
var ResTxt: Text; b64: Codeunit "Base64 Convert"; InStr: InStream; OutStr: OutStream; tmpBlob: Codeunit "Temp Blob"; Text2QrCode: Text; MyTable: Record "My Table"; begin Text2QrCode := 'Your data to convert in QR Code'; ResTxt := GetQRCode(Text2QrCode); tmpBlob.CreateOutStream(OutStr); b64.FromBase64(ResTxt, OutStr); tmpBlob.CreateInStream(InStr); MyTable.QRCode.ImportStream(InStr, 'QR code', 'image/png'); end;
Answers
How can I create a QR code image and Save as an Image to a field. Any command or codeunit available for the purpose of creating a QR code image in memory?
In BC OnPrem you can use dotNet, so theres is a solution:
You need to use the QRCoder DLL and this is the DotNet declaration:
Here is the link to get the DLL
https://github.com/codebude/QRCoder/packages/1072246
And to use the procedure and save in a media field (QRCode) inside the table "My Table" :
Regards.
Thank you very much. Really appreciate your help.
I didn't just copy paste. Your post helped me to learn
1. How to build a .net dll (project from GIT forced me to download Visual Studio 2022)
2. Where to put that DLL in the server (ad-ins folded)
3. Where to place the dll in the VS Code folder (.netpackages)
4. How to declare a dotnet assembly and how to refer it from other pages.
5. create QR code, store it as TEXT and convert to image and save to a image field.
and more.
Thank you once again