QR Code Generation and Save to Blob Field

slmaluwa
Member Posts: 366
Business Central On Prem - Latest
Could some one help to create a QR code and save it to a blob or image field? Later to display it on a page as an image?
In reports, they say it is easy use a 2D font. but, here want to create and save internally.
Could some one help to create a QR code and save it to a blob or image field? Later to display it on a page as an image?
In reports, they say it is easy use a 2D font. but, here want to create and save internally.
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."
0
Best Answer
-
Hello @slmaluwa,
In BC OnPrem you can use dotNet, so theres is a solution: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;
You need to use the QRCoder DLL and this is the DotNet declaration: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") { } }
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" :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;
Regards.0
Answers
-
To clarify, I am trying to learn
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?
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."0 -
Hello @slmaluwa,
In BC OnPrem you can use dotNet, so theres is a solution: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;
You need to use the QRCoder DLL and this is the DotNet declaration: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") { } }
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" :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;
Regards.0 -
Hello @slmaluwa,
In BC OnPrem you can use dotNet, so theres is a solution: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;
You need to use the QRCoder DLL and this is the DotNet declaration: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") { } }
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" :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;
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
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions