-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentify-micro-pdf417-code128-emulation-flag-and-handle-accordingly-in-processing-logic.cs
More file actions
113 lines (98 loc) · 4.7 KB
/
Copy pathidentify-micro-pdf417-code128-emulation-flag-and-handle-accordingly-in-processing-logic.cs
File metadata and controls
113 lines (98 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Title: MicroPdf417 Code128 Emulation Detection Example
// Description: Demonstrates generating MicroPdf417 barcodes with and without the Code128 emulation flag and reading the flag during decoding.
// Prompt: Identify Micro PDF417 Code128 emulation flag and handle accordingly in processing logic.
// Tags: barcode, micropdf417, code128, emulation, generation, recognition, aspose
using System;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.BarCode.BarCodeRecognition;
/// <summary>
/// Example program that shows how to work with the MicroPdf417 Code128 emulation flag:
/// - Generates two barcodes (with and without the flag)
/// - Reads each barcode and inspects the emulation flag
/// </summary>
class Program
{
/// <summary>
/// Entry point of the example. Generates barcode images, then reads and processes them.
/// </summary>
static void Main()
{
// Sample codetext for MicroPdf417 Code128 emulation (Application Indicator + FNC1 separator)
string codeText = "a\u001d1234567890";
// Paths for temporary image files (saved in the current working directory)
string imagePathEmulation = Path.Combine(Directory.GetCurrentDirectory(), "micropdf417_emulation.png");
string imagePathNormal = Path.Combine(Directory.GetCurrentDirectory(), "micropdf417_normal.png");
// -------------------------------------------------
// 1. Generate MicroPdf417 with Code128 emulation flag
// -------------------------------------------------
using (var generator = new BarcodeGenerator(EncodeTypes.MicroPdf417, codeText))
{
// Enable Code128 emulation mode for the generated symbol
generator.Parameters.Barcode.Pdf417.IsCode128Emulation = true;
// Save image (optional, just for visual verification)
generator.Save(imagePathEmulation);
}
// -------------------------------------------------
// 2. Generate MicroPdf417 without Code128 emulation flag
// -------------------------------------------------
using (var generator = new BarcodeGenerator(EncodeTypes.MicroPdf417, codeText))
{
// Do NOT set IsCode128Emulation (defaults to false)
generator.Save(imagePathNormal);
}
// -------------------------------------------------
// 3. Read and process the barcode with emulation flag
// -------------------------------------------------
Console.WriteLine("Reading barcode with Code128 emulation flag set:");
ProcessBarcodeImage(imagePathEmulation);
// -------------------------------------------------
// 4. Read and process the barcode without emulation flag
// -------------------------------------------------
Console.WriteLine("\nReading barcode without Code128 emulation flag:");
ProcessBarcodeImage(imagePathNormal);
}
/// <summary>
/// Reads a barcode image, extracts the Code128 emulation flag, and outputs handling information.
/// </summary>
/// <param name="imagePath">Full path to the barcode image file.</param>
static void ProcessBarcodeImage(string imagePath)
{
// Verify that the image file exists before attempting to read it
if (!File.Exists(imagePath))
{
Console.WriteLine($"File not found: {imagePath}");
return;
}
// Use MicroPdf417 decode type to correctly interpret the symbol
using (var reader = new BarCodeReader(imagePath, DecodeType.MicroPdf417))
{
bool anyFound = false;
// Iterate through all detected barcodes in the image
foreach (BarCodeResult result in reader.ReadBarCodes())
{
anyFound = true;
// The IsCode128Emulation property indicates whether the barcode was generated in emulation mode
bool isEmulation = result.Extended.Pdf417.IsCode128Emulation;
// Output basic barcode information
Console.WriteLine($"CodeText: {result.CodeText}");
Console.WriteLine($"IsCode128Emulation: {isEmulation}");
// Custom handling based on the emulation flag
if (isEmulation)
{
Console.WriteLine("-> Detected Code128 emulation mode. Process accordingly.");
}
else
{
Console.WriteLine("-> Standard MicroPdf417 mode.");
}
}
// Inform the user if no barcodes were detected
if (!anyFound)
{
Console.WriteLine("No barcodes were detected in the image.");
}
}
}
}