FAQ TBarCode .NET
How To Create a Linear Barcode in C/AL (Dynamics NAV)?
How To Create a Linear Barcode in C/AL (Dynamics NAV)?
Import the Assemblies in dotnet.al:
dotnet
{
assembly(TECIT.TBarCode)
{
type(TECIT.TBarCode.Barcode; barcode) { }
type(TECIT.TBarCode.BarcodeType; barcodeType) { }
type(TECIT.TBarCode.CodePage; codePage) { }
type(TECIT.TBarCode.CheckdigitMethod; checkDigitMethod) { }
}
assembly(System.Drawing)
{
type(System.Drawing.Rectangle; barcodeRectangle) { }
type(System.Drawing.Bitmap; barcodeBitmap) { }
}
}
Use them as follows:
barcode := barcode.Barcode;
//barcode.License(your license data);
barcode.BarcodeType := barcodeType.Code128;
barcode.Dpi := 300;
barcode.Data := yourDataToEncode;
// barcode.TranslateEscapeSequences := TRUE; // optional
// calculate optimal width in Pixel with scaling factor (1 Module = 3 Pixels)
optimalWidthPx := 3 * barcode.CalculateNumberOfModules();
// set optimal width for the bitmap (works for linear codes)
barcode.BoundingRectangle := barcodeRectangle.Rectangle(0, 0, optimalWidthPx, 300);
FileNameBmp := Filemanagement.ServerTempFileName('bmp');
barcode.Draw(FileNameBmp, 0); // save as BMP format (0 = BMP)
Click here for more information: Call .NET Framework Types From C/AL Code in Dynamics NAV
Example function for Nav 2017
This function returns a BMP image in a TempBlob record:
PROCEDURE CreateCode128 (Data2Encode : Text[100]; ScaleX: Integer, HeightPx : Integer; VAR TempBlob : TEMPORARY Record 99008535);
VAR
barcode : DotNet "'TECIT.TBarCode, Version=11.10.0.0, Culture=neutral, PublicKeyToken=1b5f4306b234b83d'.TECIT.TBarCode.Barcode";
bctype : DotNet "'TECIT.TBarCode, Version=11.10.0.0, Culture=neutral, PublicKeyToken=1b5f4306b234b83d'.TECIT.TBarCode.BarcodeType";
rectangle : DotNet "'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Drawing.Rectangle";
widthPx : Integer;
BEGIN
FileNameBmp := FileManagement.ServerTempFileName('bmp');
barcode := barcode.Barcode;
//barcode.License(your license data);
barcode.BarcodeType := bctype.Code128;
barcode.Dpi := 300;
barcode.Data := Data2Encode;
// barcode.TranslateEscapeSequences := TRUE; // optional
// calculate optimal width in Pixel with scaling factor (ScaleX =3 -> 1 Module = 3 Pixels)
widthPx := ScaleX * barcode.CalculateNumberOfModules();
// set optimal width for the bitmap (works for linear codes)
barcode.BoundingRectangle := rectangle.Rectangle(0, 0, widthPx, HeightPx);
barcode.Draw(FileNameBmp, 0); // save as BMP format (0 = BMP)
CLEAR(TempBlob);
IF TempBlob.INSERT THEN;
FileManagement.BLOBImportFromServerFile(TempBlob, FileNameBmp);
TempBlob.MODIFY;
END;
2D Code
For a 2D Matrix Code change the size calculation as follows:
widthPx := Scale * barcode.CalculateXColumnsOf2DBarcode (); heightPx := Scale * barcode.CalculateXRowsOf2DBarcode (); barcode.BoundingRectangle := rectangle.Rectangle(0, 0, widthPx, heightPx);
- Scale is a factor that determines how many pixels a matrix point in the QR code should consist of.
- A module width of 0.423 mm is achieved with 300 dpi and Scale=5. A module width of 0.381 mm is achieved with 600 dpi and Scale=9.
- If necessary, the matrix can be fixed to a specific QR code version (but then the capacity would also be limited).
- If UTF-8 is required as encoding (instead of Latin-1), you can set the code page in the barcode to UTF-8 (must be supported by the reader!):
barcode.CodePage := codePage.Utf_8;