Business Central provides the possibility to print barcodes, which is an essential tool for managing inventory and keeping track of product information. In this post, you will learn how to easily print bar codes and labels in Microsoft Dynamics 365 Business Central.
- Printing Bar Codes On Cloud
- Printing Bar Codes On-Prem
Printing Bar Codes On Cloud
For cloud environments, Microsoft provides the license for the fonts. They are ready without additional development. The provider of the fonts is IDAutomation.
The implementation process of printing barcodes is simple and straightforward. For this demonstration, we will focus on printing barcodes for items. To achieve this, we will require a report object with the ‘Item’ table as the only dataitem. In terms of layout, we will use an RDLC layout for this example.
The dataitem will include the fields that we want to display on the label. We will include the item number, description, and an encoded version of the item number.
It is important to note that we need to encode the item number in the desired format. There are several barcode formats available to choose from:
We will add the encoding logic on the ‘OnAfterGetRecord’ trigger. Note that we use the Enum called ‘Barcode Font Provider’.
We use the ‘Barcode Font Provider’ interface to check if it´s possible to encode and encode the item number.
The validation should throw an error if the input text is in an invalid format or if the symbology is not supported by the provider.
Finally, all that’s left to do is to add the fields to the layout and get the label:
If you don´t have the fonts installed in your machine for testing you can define the font in the rdl file like the following:
And the result label printed:
Get more information about printing bar codes in the Microsoft documentation:
If we wish to print QR codes (2D) the procedure is the same. The only difference is the variables used. For them, we can use the following Enum and Interface where these symbologies are available:
Printing Bar Codes On-Prem
As Microsoft says:
With Business Central on-premises, you’ll have to install the barcode fonts on the computer that runs the Business Central Server. As a minimum, you must install the fonts for the user that runs the Business Central Server instance, that is, the service account. It’s easiest just to install the font for all users.
This means that for On-Prem environments, the fonts are not available for free from IDAutomation, you´ll need to purchase them. However, there are other providers of free fonts online. You will need to install the fonts for each user.
See how to do it in the documentation from Microsoft:
With the next approach, you will be able to print bar codes without the need to install fonts locally.
Printing Bar Codes Without Fonts
If you can´t find a free font provider or don´t want to keep installing fonts locally you can take this approach where fonts aren´t needed. This method works for on-prem and cloud environments.
Instead of using fonts, a website will generate the barcode which will be saved as an image. The provider is the following:
Its API will return the image of the bar code. So we will save the image in a Media file. And then, show it on the report.
The way to do it is similar to the above. The difference is that we will get the image from a custom field called ‘Bar Code Picture’, which is an extended Media field that can be placed in a set-up table.
The procedure looks like the following. Note how we create the URL by providing the item number, the symbology, and the image type.
Then, with an HttpClient we make the request and store the result in the Media field with the help of an Instream.
For testing, you can use the item picture and preview the label on the factbox. Take into account that Media types can only be seen on factboxes or tiles:
If you want to learn more about Instreams and OutStreams for importing images follow the article below:
Follow the Microsoft documentation for creating bar codes for on-premises
That´s all. Hope you find it helpful.