In Microsoft Dynamics AX we usually need to use and print barcodes on:
- Various business documents such as invoices, orders, packing slips, receipts, etc.
- Different kinds of labels such as product and shelf labels, packaging and shipping labels, etc.
What barcodes actually are
Barcodes represent some data (Item ID, Expiration date, etc.) in the form graphic images containing parallel lines (bars) of varying widths and spacings between the bars. These are so called linear or one-dimensional (1D) barcodes. Matrix or two-dimensional (2D) barcodes use rectangles, dots, hexagons and other geometric patterns in two dimensions to represent the data.
And the mapping between data and barcode graphics is called a symbology. The specification of a symbology includes the encoding of the single digits/characters of the data as well as the start and stop markers into bars and space, the size of the quiet zone required before and after the barcode, as well as the computation of a checksum.
Types of barcodes:
- Linear (1D) barcodes
Code 128, Code 39, Codebar, EAN-13, EAN-8, Interleaved 2 of 5, UPC-A, MSI, PDF-417, Pleassey, etc.
- Matrix (2D) barcodes
QR Code, Aztec Code, Data Matrix, etc.
Barcodes can be read by special optical scanners called barcode readers, and also by applications that can read images for devices such as smartphones with cameras, etc.
You can read more about symbologies and related stuff about barcodes on Wikipedia.
Printing barcodes
Hence, if we want to print some data (e.g. Item ID, Expiration date or Serial number) from AX as a barcode of the special symbology, the data should be ‘mapped’, i.e. encoded into barcode graphics.
There are 3 main ways to create barcode graphics from the input data for the chosen symbology:
- By creating a new string that has to be used with a specific barcode font.
- By creating an instruction pattern how to draw a bit-map (raster) image representing the resulting barcode.
- By creating an instruction pattern how to draw a vector image representing the resulting barcode.
As it is known, Dynamics AX uses barcode fonts to print barcodes in SSRS reports that cover both business documents and labels.
AX Barcode classes
Encoding data to strings to be used with barcode fonts
There are utility classes with Barcode as the base class which contain algorithms for encoding data for a specific symbology (e.g. Code 128, UPC, EAN). The barcodeStr() method of each Barcode class (e.g. BarcodeCode128) encodes an input string and returns the new one that is used for barcode printing with a specific font (e.g. BC C128 HD Wide). And if we want to add a new symbology, we have to introduce a new inherited class and write the appropriate encoding algorithm method.
Support for application barcode standards
However, an AX Barcode class can also define an application standard within the particular symbology. For example, the BarcodeEAN128 class implements GS1-128, an application standard within the Code 128 barcode that enables including additional information about the product such as production date, packing date, expiration date, serial number, lot number, etc. in the barcode, saved in so called Application Identifiers (AI).
In the GS1-128 barcode on the label above the following AIs are included:
(01) Global Trade Item Number (GTIN)
(15) Best Before Date (YYMMDD)
(10) Batch/Lot Number
A better solution for printing barcodes
As said before, Dynamics AX uses barcode fonts to print barcodes. Dynamics AX decided to use this strategy because SSRS supports printing barcodes only by using barcode fonts. If SSRS had some kind of a vector barcode image generator, it would be certainly a simpler and better solution. Firstly, no encoding should have taken place on AX side, since the data (as is) would be used (and validated) directly in SSRS instead. Second, we wouldn’t have to create a new class to support a new barcode symbology. And third, the main benefit would be the use of far more suitable vector graphics instead of barcode fonts.
Advantages of using barcode as vector graphics
Vector graphics are perfect for defining barcode images. A vector image is a set of drawing commands that precisely defines the edges of each bar and specifies how to fill in the area created within the defined edges. Vector images are completely device independent as they are a set of precise commands instead of a collection of dots. When a vector image is sent to a general printer the printer’s software converts it to a raster image so that it can print it. They are much smaller than bit-map images so they print many times faster.
Disadvantages of using barcode as fonts and bit-map images
On the contrary, the Uniform Code Council does not recommend the use of fonts for printing barcodes. There are potential problems with EAN/UPC, and especially with 2D symbologies when using fonts; the bar width cannot be specified exactly in printer dots, bearer bars and quiet zones are not supported, etc.
Disadvantages of using bit-map images for barcodes are that they strictly depend on printer resolution. A barcode will print as smaller image on a printer with higher resolution. Also for high resolution printers, a size of bit-maps images representing barcodes becomes very large which affects not just computer memory but also speed of printing.
What can we do about it in Dynamics AX
Thus, the best possible solution would be to have a vector barcode generator already embedded in our reporting tool. This way we would benefit from optimal barcode printing as well as we would avoid complicated encoding algorithms on AX side – we wouldn’t need them anymore.
Now, the question is, what can we do about it in Dynamics AX? Can we upgrade SSRS reports to print barcodes using vector graphics? Or can we at least expect some improvements from Microsoft in this regard, or regarding SSRS reporting in general? I am afraid that the answer is presumably No.
Microsoft will probably stay focused on the new aspects of AX in cloud while leaning on community of partners and ISVs to deliver more powerful reporting solutions.
Third-party solutions for printing barcodes in Dynamics AX
There are some excellent third-party solutions on the market specialized, e.g. for printing labels including barcodes. But probably it would be great to have a comprehensive reporting tool, completely integrated with Dynamics AX, which offers smooth use of barcodes with business documents likewise printing barcodes on labels.
Printing barcodes with Docentric AX
Docentric AX is an Dynamics AX Add-On that improves SSRS reporting in general, enabling you to design reports directly in MS Word, using all Word’s powerful features. Regarding barcodes, you can print both 1D and 2D barcodes using vector graphics. For example, you can print Invoice ID as QR Code on your Customer invoices, or print product serial numbers on Sales packing slips as EAN-13 barcodes. You can also use Docentric AX to design and print labels with barcodes.
Printing barcodes on business documents
Let’s say that we want to print Invoice ID as a barcode on Free Text Invoice.
Let’s see how it works. On the Free Text Invoice report template, which is an ordinary Word document, we simply insert a Barcode tagging element at the desired location, by clicking the Barcode button from the Tagging Elements button group in the Docentric AX ribbon in MS Word. Then we need to bind it directly to the Invoice ID data field from the report data source and to select the wanted barcode symbology in the Barcode Properties panel of the Element Tree pane. Note that we are not using any of the AX Barcode classes to achieve the wanted result.
Support for 2D symbologies
In this example we use QR Code, a 2D barcode symbology. As we mentioned before, SSRS uses barcode fonts for printing barcodes, which is not a reliable approach especially for 2D barcodes. Docentric AX designer automatically generates a vector barcode image for the selected data from the report data source and the selected barcode symbology.
Changing the barcode symbology
To change the symbology for the barcode representing Invoice ID from QR Code to, let’s say, Code 128, simply select the new symbology from the Symbology combobox located in the Barcode Properties panel for the selected Barcode tagging element. The change is visible immediately.
Resizing, rotating and formatting barcodes
Barcode tagging elements in Docentric AX designer are in fact MS Word Shapes, which are vector images. Thus we can resize them, rotate them, change their background color and do anything that can normally be done with Shapes in MS Word.
At report generation time, i.e. when report is executed from AX or previewed from the designer, Barcode tagging elements are replaced with the vector images of the selected Barcode representing the run-time data.
GS1-128 application barcode standard
However, for building a barcode that meets GS1-128 application standard, we must continue to use the BarcodeEAN128 class and its methods such as itemId(), palletId(), serialId(), qty(), etc. to get a proper barcode structure. Afterwards we can bind a Barcode tagging element in Docentric AX designer to the result of the barcodeEAN128.barcodeStrHR() method with the parentheses removed. We don’t have to invoke the encode() method first. Please see the example below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
BarcodeEAN128 barcodeEAN128; barcodeEAN128 = BarcodeEAN128::construct(); barcodeEAN128.itemId(true, '3000'); barcodeEAN128.qty(true, 64); // We don't need to invoke the encoding algorithm anymore. // barcodeEAN128.encode(); // We don't need this string since we don't use barcode fonts for printing barcodes. // info(barcodeEAN128.barcodeStr()); info(barcodeEAN128.barcodeStrHR()); // The output: '(01)00000000030007(30)64' -> '01000000000300073064' // We will use the second string in the designer. |
In this example the barcodeStrHR() method returns the string ‘(01)00000000030007(30)64’, but we need to bind ‘01000000000300073064’, the string without the parentheses, to a Barcode tagging element in Docentric AX designer. This is actually the same value we would get if we scanned this barcode using the scanner, e.g. in Item Arrival Journal in the Inventory and warehouse management module, or Picking Route ID in the WMSPickingRoute table.
Printing labels
With Docentric AX you can also design and print label sheets with labels containing 1D or 2D barcodes.
If you are interested in printing labels using Docentric AX, please find more information here:
How to create and print product labels in Retail module by using Docentric AX >>
How to design labels in MS Word with Docentric AX designer >>
I need to print 2D bar codes using AX 4.0. Does Docentric work with AX 4.0?
We are using SSRS reports with our AX build.
Hi Amber,
Thanks for the question. Our reporting solution integrates deeply in Dynamics AX. But currently we only support AX 2012 and AX7. It is hard to say when we will add support for older versions as well.