FAQ TBarCode .NET
Come creare un codice a barre lineare in C/AL (Dynamics NAV)?
Come creare un codice a barre lineare in C/AL (Dynamics NAV)?
Importate gli assembly 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) { }
}
}
Usateli come segue:
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)
Fate clic qui per maggiori informazioni: Call .NET Framework Types From C/AL Code in Dynamics NAV
Funzione di esempio per Nav 2017
Questa funzione restituisce un'immagine BMP in un record TempBlob:
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;
Codice 2D
Per un codice matrice 2D modificate il calcolo dimensioni come segue:
widthPx := Scale * barcode.CalculateXColumnsOf2DBarcode (); heightPx := Scale * barcode.CalculateXRowsOf2DBarcode (); barcode.BoundingRectangle := rectangle.Rectangle(0, 0, widthPx, heightPx);
- Scale è un fattore che determina da quanti pixel dovrebbe essere composto un punto della matrice nel codice QR.
- Una larghezza modulo di 0,423 mm si ottiene con 300 dpi e Scale=5. Una larghezza modulo di 0,381 mm si ottiene con 600 dpi e Scale=9.
- Se necessario, la matrice può essere fissata a una versione specifica del codice QR (ma in tal caso anche la capacità sarebbe limitata).
- Se è richiesto UTF-8 come codifica (anziché Latin-1), potete impostare la code page nel codice a barre su UTF-8 (deve essere supportata dal lettore!):
barcode.CodePage := codePage.Utf_8;