ITF-14 และ Interleaved 2 of 5 (I-2/5) เป็นสัญลักษณ์เชิงเส้นสําหรับ cartons, pallets, และ logistics ภายใน ITF-14-codes a GTIN-14** (14 หมายเลขรวมถึงตัวเลขตรวจสอบ Mod-10) and is commonly printed with bearer bars on corugated cardboard. I-2/5 is a compact, numeric-only, even-length symbology often used for internal trays and cases.

ตัวอย่างเต็มรูปแบบ ( Copy-Paste Ready)

สิ่งที่คุณได้รับ:

  • หนึ่งแอปคอนโซล .NET ที่สามารถส่งรหัสบาร์ ITF-14 และ I-2/5
  • A GTIN-14 check digit ผู้ช่วยสําหรับ ITF-14.
  • การประยุกต์ใช้ระยะสั้น สําหรับ I-2/5.
  • ความผิดพลาดที่ไวต่อการพิมพ์ (ความหนาแน่นของแถบความสูง)
  • การผลิต PNG โดย filename

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 หมายเลขตรวจสอบ**
  • บ่อยครั้งที่พิมพ์ขนาดใหญ่ด้วย ระบายความร้อน zones และบางครั้ง บาร์บอร์ด (กรอบรอบ ๆ รหัส) บน corugated

ในรหัส: เรายอมรับได้ถึง 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);

Interleaved 2 ของ 5 วัตถุสําคัญ

  • สัญลักษณ์ขนาดกะทัดรัด ** Numeric-only**
  • ต้องการ หมายเลขเท่ากัน (คู่จะถูกแบ่งออก)
  • เรา ด้านซ้าย-pad กับ 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 เพื่อหลีกเลี่ยงการสแกนสั้น หากโครงสร้าง Aspose.BarCode ของคุณแสดงให้เห็นถึงพารามิเตอร์บาร์พคพาที่เฉพาะเจาะจง, ปรับให้พวกเขา; ในทางอื่น ๆ, เพิ่มกรั้วใน layout labelsของคุณ.

Troubleshooting

  • ไม่มีการสแกนบน corugated: เพิ่ม XDimension, ให้ความต้านทานสูงเพิ่ม/ยืนยันโซนเงียบสงบพิจารณาสายพานลําเลียง
  • I-2/5 ถูกปฏิเสธเป็นความยาวที่แปลกใจ: คุณลืมวาง; ใช้รหัส evenData โลก
  • ITF-14 ตรวจสอบตัวเลขที่ผิด: ให้แน่ใจว่าคุณส่ง เพียง 13 หมายเลขแรก ไปยังคํานวณ; ปล่อยให้รหัสเป็นจํานวนที่ 14

แนวทางที่ดีที่สุด

  • พารามิเตอร์ล็อค (X-dimension, height, margins) in config so output is reproducible.
  • ตรวจสอบสแกนเนอร์เป้าหมายของคุณ และแท็ก media — tweak โดย การเพิ่มขนาดเล็ก
  • เวอร์ชันรูปแบบของคุณ หากคุณเพิ่มโลโก้/ข้อความด้านบนหรือด้านล่างของแถบ
  • ให้เป็นหมายเลข: I-2/5 ไม่รองรับการเข้ารหัสที่ไม่ใช่ดิจิทัล การทําความสะอาดการเข้าก่อนหน้านี้

ข้อสรุป

ด้วยเส้นโค้ดบางอย่างคุณสามารถผลิต robust, scanner-friendly ITF-14 และ Interleaved 2 of 5 barcodes ใน .NET โดยใช้ Aspose.BarCode เริ่มต้นด้วยตัวอย่างที่สมบูรณ์ข้างต้นแล้วท่อความหนาของแถบความสูงและแร่ไปยังเครื่องพิมพ์และสแกนของคุณ ตัวช่วยการตรวจสอบและระยะเวลาเดียวกันทําให้ข้อมูลมาตรฐานของคุณปลอดภัยจากจุดเริ่มต้น

More in this category