ITF-14と **Interleaved 2 of 5 (I-2/5)**は、カード、パレット、および内部ロジスティクスのためのワークホースの線形シンボルです. ITF14は *GTIN-14(モード10チェック番号を含む14桁)を暗号化し、一般的に印刷されます。
コピーパスト準備(Copy-Paste Ready)
あなたが得るもの:
- 1つの .NET コンソール アプリは ITF-14 および I-2/5 バーコードを出すことができます。
- ITF14のための GTIN-14 チェック デジタル ヘルパー。
- Even 長さの実施 I-2/5.
- 印刷のための敏感な欠陥(マージン、バー厚さ、高さ)
- フィルネームによるPNG出力。
1)プロジェクトを作成し、パッケージを追加する
dotnet new console -n ItfAndI25Demo -f net8.0
cd ItfAndI25Demo
dotnet add package Aspose.BarCode
(2)代替 Program.cs
次のとおり
using System;
using Aspose.BarCode.Generation;
namespace ItfAndI25Demo
{
class Program
{
// Usage:
// ITF-14 -> dotnet run -- itf14 400638133393 260930
// (first arg "itf14", second is GTIN base ≤13 digits; we'll compute the 14th check digit)
// I-2/5 -> dotnet run -- i25 123456789
//
// Output files:
// ITF14_<gtin14>.png
// I25_<dataEven>.png
static int Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Usage:");
Console.WriteLine(" ITF-14: dotnet run -- itf14 <gtin_base_≤13_digits> [xPixels=3] [heightMM=22] [marginMM=4]");
Console.WriteLine(" I-2/5 : dotnet run -- i25 <numeric_data> [xPixels=3] [heightMM=22] [marginMM=4]");
return 1;
}
var mode = args[0].Trim().ToLowerInvariant();
int xPixels = args.Length > 2 && int.TryParse(args[2], out var x) ? Math.Max(1, x) : 3;
float heightMM = args.Length > 3 && float.TryParse(args[3], out var h) ? Math.Max(10f, h) : 22f;
float marginMM = args.Length > 4 && float.TryParse(args[4], out var m) ? Math.Max(1f, m) : 4f;
try
{
switch (mode)
{
case "itf14":
{
string gtinBase = args[1].Trim();
if (gtinBase.Length > 13 || !IsAllDigits(gtinBase))
throw new ArgumentException("For ITF-14, provide a numeric GTIN base (≤13 digits). The 14th check digit will be computed.");
// Build full GTIN-14: left-pad to 13 digits, then add Mod-10 check digit
string gtin13 = gtinBase.PadLeft(13, '0');
char check = CalcGtin14CheckDigit(gtin13);
string gtin14 = gtin13 + check;
// ITF-14 encodes the 14-digit GTIN
using var gen = new BarCodeGenerator(EncodeTypes.ITF14, gtin14);
// Print-friendly defaults
gen.Parameters.Barcode.XDimension.Pixels = xPixels; // bar/module thickness
gen.Parameters.Barcode.BarHeight.Millimeters = heightMM;
gen.Parameters.Barcode.LeftMargin.Millimeters = marginMM;
gen.Parameters.Barcode.RightMargin.Millimeters = marginMM;
gen.Parameters.Barcode.TopMargin.Millimeters = Math.Max(2f, marginMM / 2f);
gen.Parameters.Barcode.BottomMargin.Millimeters = Math.Max(2f, marginMM / 2f);
// Optional: show human-readable text below (depends on layout preference)
gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;
gen.Parameters.Barcode.CodeTextParameters.FontSize.Point = 8f;
// Save PNG (lossless)
string file = $"ITF14_{gtin14}.png";
gen.Save(file, BarCodeImageFormat.Png);
Console.WriteLine($"✅ ITF-14 saved: {file}");
break;
}
case "i25":
case "interleaved2of5":
case "interleaved_2_of_5":
{
string data = args[1].Trim();
if (!IsAllDigits(data))
throw new ArgumentException("I-2/5 requires numeric data.");
// I-2/5 needs an even number of digits; if odd, left-pad with '0'
string evenData = data.Length % 2 == 0 ? data : "0" + data;
using var gen = new BarCodeGenerator(EncodeTypes.Interleaved2of5, evenData);
// Print-friendly defaults
gen.Parameters.Barcode.XDimension.Pixels = xPixels;
gen.Parameters.Barcode.BarHeight.Millimeters = heightMM;
gen.Parameters.Barcode.LeftMargin.Millimeters = marginMM;
gen.Parameters.Barcode.RightMargin.Millimeters = marginMM;
gen.Parameters.Barcode.TopMargin.Millimeters = Math.Max(2f, marginMM / 2f);
gen.Parameters.Barcode.BottomMargin.Millimeters = Math.Max(2f, marginMM / 2f);
gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;
gen.Parameters.Barcode.CodeTextParameters.FontSize.Point = 8f;
string file = $"I25_{evenData}.png";
gen.Save(file, BarCodeImageFormat.Png);
Console.WriteLine($"✅ Interleaved 2 of 5 saved: {file}");
break;
}
default:
throw new ArgumentException("First argument must be 'itf14' or 'i25'.");
}
return 0;
}
catch (Exception ex)
{
Console.Error.WriteLine("❌ Error: " + ex.Message);
return 2;
}
}
// ----------------- Helpers -----------------
// GTIN-14 check digit (Mod-10). Argument must be the first 13 digits as a string.
static char CalcGtin14CheckDigit(string first13)
{
if (first13 is null || first13.Length != 13 || !IsAllDigits(first13))
throw new ArgumentException("CalcGtin14CheckDigit expects 13 numeric digits.");
int sum = 0;
// Rightmost (position 13) is index 12; multiply alternating by 3 and 1, starting with 3 on the right.
// From the rightmost toward left: 3,1,3,1,...
for (int i = 0; i < 13; i++)
{
int digit = first13[12 - i] - '0';
int weight = (i % 2 == 0) ? 3 : 1;
sum += digit * weight;
}
int mod = sum % 10;
int check = (10 - mod) % 10;
return (char)('0' + check);
}
static bool IsAllDigits(string s)
{
if (string.IsNullOrEmpty(s)) return false;
foreach (char c in s)
if (c < '0' || c > '9') return false;
return true;
}
}
}
(3)いくつかの例を挙げる
# ITF-14: pass ≤13 digits, we compute the 14th check digit
dotnet run -- itf14 400638133393
# -> ITF14_0400638133393X.png (X = computed check digit)
# Interleaved 2 of 5: any numeric string; we pad a leading 0 if odd length
dotnet run -- i25 123456789
# -> I25_0123456789.png
Step-by-Step(コードが何をしているのか)
ITF14の重要性
- 暗号化する GTIN-14(合計14桁)
- 最後の数字は「Mod-10」です。
- 頻繁に大きな印刷 リラックスゾーン と時には ベーラーバー (コードの周りのフレーム) をコラグレート。
コード: で 13 桁まで受け入れ、13 位に貼り付け、14 番を計算し、すべての 14 数字を送信します。 EncodeTypes.ITF14
.
string gtin13 = gtinBase.PadLeft(13, '0');
char check = CalcGtin14CheckDigit(gtin13);
string gtin14 = gtin13 + check;
using var gen = new BarCodeGenerator(EncodeTypes.ITF14, gtin14);
関数 2 / 5 重要性
- コンパクト、 数字のみ シンボロジー
- 数字の数と同じ(カップルが交差する)が必要です。
- 私たちは 左パッド と共に
0
入力が長い場合
string evenData = data.Length % 2 == 0 ? data : "0" + data;
using var gen = new BarCodeGenerator(EncodeTypes.Interleaved2of5, evenData);
印刷友好デフォルト
- *Xサイズ(バー/モジュール厚さ)
3 px
熱プリンターの実用的な出発点です。 - バーの高さ*:
~22 mm
1×3′′または2×1′′ラベルでうまく機能し、ストアに調整します。 - 「Quiet Zones」
~4 mm
左 / 右2–3 mm
トップ・ベッド - タイトル(英名):Human-readable text**: show below (
CodeLocation.Below
ラベルがテキストを必要とする場合
gen.Parameters.Barcode.XDimension.Pixels = 3;
gen.Parameters.Barcode.BarHeight.Millimeters = 22f;
gen.Parameters.Barcode.LeftMargin.Millimeters = 4f;
gen.Parameters.Barcode.RightMargin.Millimeters = 4f;
gen.Parameters.Barcode.TopMargin.Millimeters = 2f;
gen.Parameters.Barcode.BottomMargin.Millimeters = 2f;
gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;
gen.Parameters.Barcode.CodeTextParameters.FontSize.Point = 8f;
カスタマイズアイデア
Bigger ラベル / 厳しいメディア → 増加
XDimension
に4–5 px
.タブレットの高さを減らす(
18–20 mm
決して、静かな場所で飢えはしない。HRT(ヒューマン読みやすいテキスト)を削除する あなたのレイアウトが他の場所でテクストを印刷している場合:
gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
**ノート(ITF-14):**多くのプリンター/スタンダードは、短いスキャンを防ぐために ITF-14周辺のフレームまたはトップ/ベースバーを好みます。
Troubleshooting
- ** スキャンされていない:** 増加
XDimension
高いコントロールを確保し、静かなゾーンを追加/確認する、携帯バーを検討します。 - I-2/5 不思議な長さとして拒否: あなたはパッドを忘れました; コードを使用する
evenData
論理 - ITF-14 チェック 数字が間違っている: 最初の 13 桁のみを計算機に送信することを確認し、コードが 14 番を数えるようにしてください。
ベストプラクティス
- ロックパラメーター(Xサイズ、高さ、マージン)を設定して出力が再生可能になります。
- ターゲットスキャナーおよびラベルメディアをチェックする - 小さなアップグレード**によるツイック。
- ** テンプレートのバージョン** あなたが上または下のバーにロゴ/テキストを追加する場合。
- 数値を保持する: I-2/5 は非数字をサポートしません。
結論
コードのいくつかのラインを使用すると、Aspose.BarCode を使用して .NET で robust, scanner-friendly ITF-14 and Interleaved 2 of 5 barcodes を生成することができます。上記の完全な例から始まり、その後、印刷機やスキャナーにバーの厚さ、高さおよびマージンをトゥーンします。