ITF-14 و Interleaved 2 از 5 (I-2/5) نمادهای خطی کارگر برای کارتون ها، پالت ها و تدارکات داخلی هستند. ITF 14 یک GTIN-14 را رمزگذاری می کند (14 عدد، از جمله شماره چک Mod-10) و به طور معمول با ** نوار حمل کننده* بر روی کارتریج پیچیده چاپ می شود.
نمونه کامل (Copy-Paste Ready)
چه چیزی دریافت می کنید:
- یک برنامه کنسول .NET که می تواند ITF-14 و I-2/5 بارکد را خروجی کند.
- یک GTIN-14 چک دیجیتال کمک کننده برای ITF-14.
- استفاده از پهنای باند برای I-2/5.
- ضعف های حساس برای چاپ (مردم، ضخامت نوار، ارتفاع)
- تولید PNG با نام فیلیپین
1) ایجاد پروژه و اضافه کردن بسته
dotnet new console -n ItfAndI25Demo -f net8.0
cd ItfAndI25Demo
dotnet add package Aspose.BarCode
۲) جایگزین 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
گام به گام (چه چیزی کد انجام می دهد)
ITF-14 مهم
- رمزگذاری یک GTIN-14 (14 عدد در مجموع).
- آخرین عدد یک عدد Mod-10 ** چک** است.
- اغلب چاپ بزرگ با منطقه آرامش و گاهی اوقات ** نوار حمل** (یک چارچوب در اطراف کد) بر روی corrugated.
در کد: ما تا 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-Dimension** (تراکم نوار / ماژول) :
3 px
این یک نقطه شروع برای پرینترهای حرارتی است. - ** ارتفاع بار * :
~22 mm
به خوبی بر روی برچسب های 1×3′′ یا 2×1′′ کار می کند؛ برای ذخیره سازی خود تنظیم کنید. - *تغییرمسیرهای منطقه ای :
~4 mm
چپ و راست؛2–3 mm
بالا و پایین - **تصویر قابل خواندن **: نمایش در زیر (
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;
ایده های سفارشی سازی
برچسب های بزرگتر / رسانه های سخت → افزایش
XDimension
برای4–5 px
.برچسب های ضخیم تر → کاهش ارتفاع نوار (
18–20 mm
اما هرگز در مناطق آرام گرسنه نباشید.Suppress HRT (نص قابل خواندن انسان) اگر طرح شما متن را در جای دیگری چاپ کند:
gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
نکته بر روی نوار حمل کننده (ITF-14): بسیاری از پرینترها/معیارهای ترجیح می دهند یک چارچوب یا بالای/کلاه پایین در اطراف ITF-14 برای جلوگیری از اسکن های کوتاه.اگر Aspose.BarCode ساختار خود را نشان می دهد پارامترهای خاص IT F بار، آنها را فعال کنید؛ در غیر این صورت، اضافه کردن فریم به طرح برچسب خود.
Troubleshooting
- ** بدون اسکن بر روی corrugated:** افزایش
XDimension
تضمین کنتراست بالا، اضافه کردن / تأیید مناطق آرام، در نظر گرفتن نوار حمل کننده. - I-2/5 به عنوان طول عجیب رد شده است: شما فراموش کرده اید که بسته بندی؛ استفاده از کد
evenData
منطق است. - ** ITF-14 اعداد را اشتباه چک کنید:** اطمینان حاصل کنید که فقط 13 عدد اول را به محاسبهگر منتقل می کنید؛ اجازه دهید کد 14 را شمارش کند.
بهترین شیوهها
- ** پارامترهای قفل** (X-dimension، height، margins) در پیکربندی به طوری که خروجی قابل بازسازی است.
- ** بر روی اسکنر هدف خود چک کنید** و رسانه های برچسب گذاری – با ** افزایش کوچک** تکیه کنید.
- نسخه قالب های خود را اگر شما اضافه کردن لوگو / متن در بالای یا زیر نوار.
- باید آن را عددی نگه دارید: I-2/5 از دیجیتال های غیر پشتیبانی نمی کند؛ ورودی ها را زودتر تمیز کنید.
نتیجه گیری
با چند خط کد، شما می توانید Robust، اسکنر دوستانه ITF-14 و Interleaved 2 از 5 بارکد در .NET با استفاده از Aspose.BarCode تولید کنید.با نمونه کامل بالا شروع کنید، سپس ضخامت نوار، ارتفاع و لبه ها را به پرینترها و اسکانر های خود تنظیم دهید.