ITF-14 및 **Interleaved 2 of 5 (I-2/5)**는 카트리지, 팔레트 및 내부 물류를위한 라인 상징입니다. ITF-14, 모드-10 체크 디지털을 포함하여 14 숫자 **GTIN-14)를 암호화하고 일반적으로 인쇄됩니다.
완전한 예제 (Copy-Paste Ready)
당신이 얻는 것 :
- 한 .NET 콘솔 앱은 ITF-14 및 I-2/5 바코드를 출력할 수 있습니다.
- ITF-14에 대한 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
단계-단계 (코드가 무엇을하고 있는지)
ITF-14 필수 요소
- 암호화 GTIN-14 (14 숫자 총)
- 마지막 숫자는 Mod-10 ** 체크 디지털**입니다.
- 종종 quiet zones와 때로는 bearer bars (코드 주위의 프레임)로 큰 인쇄가 흐려집니다.
** 코드:** 우리는 최대 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);
5개의 필수 요소 중 2개
- 컴팩트한, ** 숫자 - 단순한** 상징
- 똑같은 숫자 수가 필요합니다** (쌍이 섞여있다).
- 우리는 ** 왼쪽 패드**와 함께
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 영역 :
~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
그러나 절대 조용한 영역에서 배고프지 않는다.HRT (인간 읽을 수 있는 텍스트)를 억제하십시오. 당신의 레이아웃이 다른 곳에서 문서를 인쇄하는 경우:
gen.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
노트 바 (ITF-14) : 많은 프린터 / 표준은 짧은 스캔을 방지하기 위해 ITF-14 주위의 프레임 또는 상단 / 하단 바를 선호합니다.
Troubleshooting
- Corrugated에 스캔되지 않습니다: 증가
XDimension
, 높은 대조를 보장, 추가 / 확인 조용한 영역, 운반자 바를 고려. - I-2/5 이상한 길이로 거부: 당신은 패드를 잊어 버렸습니다; 코드를 사용하십시오
evenData
논리 입니다 - ITF-14 숫자를 잘못 확인하십시오: 최초의 13자리만 계산기에 전달하도록 하십시오.
모범 사례
- Lock parameters (X-dimension, height, margins) in config 그래서 출력은 재생할 수 있습니다.
- 당신의 대상 스캐너 및 라벨 미디어를 확인하십시오 - 작은 증가에 의해 흡수됩니다.
- 당신의 템플릿을 버전 당신이 위 또는 아래 바에 로고 / 텍스트를 추가하는 경우.
- 그것을 숫자로 유지하십시오: I-2/5는 비 디지털을 지원하지 않습니다; 입력을 일찍 정화합니다.
결론
몇 개의 코드 라인으로, 당신은 Aspose.BarCode를 사용하여 .NET에서 robust, 스캐너 친화적 인 ITF-14 및 Interleaved 5 바코드를 생산할 수 있습니다. 위의 완전한 예로 시작한 다음 프린터 및 스캔에 바 두께, 높이 및 마진을 튜닝합니다. 체크 디지털 및 동일한 길이 도우미는 데이터 표준을 처음부터 안전하게 만듭니다.