I'm aware that we could create an Azure service and call it from NAV (https://github.com/Microsoft/AL/issues/744), but including barcodes/QRs in reports is something that many customers request, and it seems odd to require an external service + associated costs just to do it, specially when Microsoft could solve it by including ZXing (https://github.com/micjahn/ZXing.Net) and creating a wrapper codeunit so that we could invoke it.
(And, let's be fair, some customers are still a bit reluctant to move to the cloud. Anything that's harder to implement in BC than on premise, it's just another excuse for them to stay on premise)
We've actually done something similar ourselves in the past, and an AL function with this signature:
Encode(Value: Code[1024], Format: 'AZTEC,CODBAR,CODE39...', Height: Integer, Width: Integer, VAR TempBlob: TEMPORARY Record TempBlob)
Would allow us (partners) to include barcodes in reports, without external costs, and without the need for every partner to reimplement the same code.
I can understand the security implications of adding extra DLLs to Business Central, and that for Microsoft this is not so simple as just including a DLL and call it a day, but I also think that this would greatly help developers, cover a use case that many customers require, and give an edge to BC over other ERPs that don't include this functionality as standard (or compete with others that do include it).
This is indeed a very important issue for the future. From my point of view it would be best if Microsoft could provide an Azure service here itself, or a corresponding DLL on the ServiceTier. To my knowledge Microsoft already uses the Aspose.Word DLL for the PDF conversion. This applies to the standard Word reports. Here is a function to which you pass the path to the original Word document, and you can then convert it to PDF without Word being installed on the server. And in the PDF properties you will find the Aspose library. A customer once drew our attention to this because he thought that Dynamics NAV was here. Instead, a product that was completely new to us at the time was in the document properties. But the Aspose DLL is not stored in the ServiceTier directory, I couldn't find it. I assume that Microsoft has hidden it in some other DLL.
Maybe Microsoft could do the same here, and provide the Aspose.barcode DLL as wrapper, because it supports almost all barcodes available. This belongs either in an Azure service, or in the ServiceTier directories + own wrapper code unit. This would make it very easy to generate and reuse barcodes in the future. Just to give you a little idea.
You could just create a rest service that returns a base64 encoded barcode image. If you can wait a few days, I'd be happy to provide you with a code sample to set up an app service or azure function.
@erikrijn Thanks a lot for offering an example on how to create such a service, but this ticket is precisely about being able to do it without calling/deploying an external service!
Well Microsoft has been clear from the beginning that additions like this will have to be done using API's. Sure you might find this addition super important, but along comes the next person who needs something else which he/she considers core functionality. And so on, and so on.
Thanks for the suggestion. We will have another discussion between the teams on this topic. As it was correctly mentioned, it's not a straightforward process to host a 3rd party DLL on Business Central servers.
We'd like to see some sort of native Barcode encoding mechanism too. We could use an Azure function, but there'll be a latency involved which would be tricky to work around. E.g. generating unique labels for hundreds of items on an order would take forever to generate the barcodes and bring them back into the system.
Agree, Use either Zxing of any other Encoding library, is core functionality in the current ERP world where tracebility is an ever increasing demand, and using barcoding for this is eminent. Latency is also my worry using the Azure functions. Simple wrapper function being able to create barcodes please. You can get our function for free microsoft but I think building one yourself would take your guys max 4 days
You could just create a rest service that returns a base64 encoded barcode image. If you can wait a few days, I'd be happy to provide you with a code sample to set up an app service or azure function.
@erikrijn As every ISV, we're looking into moving our Barcode bitmap creator (using xzing) towards an Azure function. We're facing some issues right now, since System.Drawing seems not supported in the Azure function. Any hints on how to move forward? (without having to wait for the nth release where MS will eventually come up with a standard solution)
@fvet Hi Fr茅d茅ric, this is an example that I did a couple of years ago for an AL + Azure Functions course that I taught, so it might have change a bit since then, but here is how I generated barcodes in an Azure Function using ZXing:
// If I remember correctly, using SixLabors.ImageSharp was the key to be able to generate the barcode without
// System.Drawing.
(...)
using ZXing;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
(....)
// The function had a main method that called this function to generate the barcode.
public static string GetBase64Image(string barcode,int width,int height)
{
var encodingOptions = new ZXing.Common.EncodingOptions();
encodingOptions.Height = height;
encodingOptions.Width = width;
var barcodeWriter = new ZXing.ImageSharp.BarcodeWriter<Rgba32>();
barcodeWriter.Options = encodingOptions;
barcodeWriter.Format = BarcodeFormat.CODE_128;
using(var image = barcodeWriter.Write(barcode))
{
return image.ToBase64String(ImageFormats.Png);
}
}
// And these were the nuget packages used by the function. As you can see from the Sdk version, this is an old example, so things might be slightly different (hopefully for the better).
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.*" />
<PackageReference Include="ZXing.Net" Version="0.16.*" />
<PackageReference Include="ZXing.Net.Bindings.ImageSharp" Version="0.16.6-beta" />
</ItemGroup>
Most helpful comment
@fvet Hi Fr茅d茅ric, this is an example that I did a couple of years ago for an AL + Azure Functions course that I taught, so it might have change a bit since then, but here is how I generated barcodes in an Azure Function using ZXing: