ITF-14 और Interleaved 2 of 5 (I-2/5) में से 2 कामकाजी कार्डबोर्ड, पैलेट और आंतरिक लोजिस्टिक्स के लिए लाइनर प्रतीक हैं. ITF-14 एक GTIN-14 (14 अंक, जिसमें एक मॉड-10 चेक डिफ़ॉल्ट शामिल है) और आमतौर पर मुद्रित किया जाता है बार्स बार्स I-2/5 एक कॉम्पैक्ट, संख्या-केवल, लंबाई प्रतीक अक्सर आंतरिक टॉयलेट और मामले के लिए उपयोग किया जाता है।.
पूर्ण उदाहरण (Copy-Paste Ready)
आप क्या प्राप्त करते हैं:
- एक .NET कंसोल ऐप जो आउटपुट कर सकता है ITF-14 और I-2/5 बारकोड.
- A GTIN-14 चेक डिजिटल ITF-14 के लिए सहायक.
- लंबी अवधि के लिए I-2 / 5 के लिए.
- प्रिंट के लिए सार्थक डिफ़ॉल्ट (मार्जिन, बार मोटाई, ऊंचाई).
- PNG फ़ाइलों के लिए फ़ाइलों का उपयोग करें।.
1) Create the project and add the package
dotnet new console -n ItfAndI25Demo -f net8.0
cd ItfAndI25Demo
dotnet add package Aspose.BarCode
2) Replace 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) Run a few examples
# 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 (कोड क्या कर रहा है)
ITF-14 के लिए आवश्यक
- कोड A GTIN-14 (सभी 14 अंक).
- के अंतिम डिजिटल एक मोड-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 mm1×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;
Customization विचारों
- बड़े लेबल / रूख मीडिया बढ़ी
XDimensionदो4–5 px. - अधिक लेबल कम से कम कम कम से कम (
18–20 mm(और कभी भी शांत क्षेत्रों में नहीं।. - HRT (Human-readable text) को रोकें यदि आपका लेआउट अन्य जगह पर पाठ प्रिंट करता है:
csharp gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
लेयर बार (ITF-14) पर नोट: कई प्रिंटर / मानक छवि या शीर्ष / नीचे बार ITF-14 के आसपास छवि या छवि को पसंद करते हैं ताकि संक्षिप्त स्कैन को रोकने के लिए।.
परेशानियों
- नहीं चलेगा गड़बड़ी: बढ़ी
XDimension, उच्च विपरीत सुनिश्चित करें, शांत क्षेत्रों को जोड़ें / पुष्टि करें, बेरर बार पर विचार करें।. - I-2/5 अजीब लंबाई के रूप में अस्वीकार किया गया: आप पैड भूल गए हैं; कोड का उपयोग करें
evenDataतर्क है।. - आईटीएफ-14 जांच डिजिटल गलत है: आप पारित करने के लिए सुनिश्चित करें केवल 13 पहला डिग्री कोड को 14वीं कोड में गिनती करें।.
सर्वश्रेष्ठ अभ्यास
- लॉगिंग पैरामीटर (X-dimension, height, margins) config में ताकि आउटपुट पुन: प्राप्त किया जा सके।.
- अपने लक्ष्य स्कैनर पर जाँच करें और लेबल मीडिया - कमजोर छोटे बढ़ोतरी.
- आपकी Templates के संस्करण यदि आप बारों के ऊपर या नीचे लोगो / पाठ जोड़ते हैं।.
- संख्या रखें:I-2/5 गैर-शब्दों का समर्थन नहीं करता है; प्रारंभिक रूप से इनपुट को स्वच्छ करें।.
निष्कर्ष
कुछ पंक्तियों के साथ, आप उत्पादित कर सकते हैं मजबूत, स्कैनर-अनुकूल ITF-14 और Interleaved 2 of 5 बारकोड .NET में Aspose.BarCode का उपयोग करें. ऊपर के पूर्ण उदाहरण से शुरू करें, फिर अपने प्रिंटर और स्कैनरों के लिए बार मोटाई, ऊंचाई और मार्जिन को टोन करें. चेक-चिकट और समान लंबाई सहायक आपके डेटा मानकों को शुरू से ही सुरक्षित बनाते हैं.