|
1 | 1 | using System; |
2 | 2 | using System.IO; |
3 | 3 | using Aspose.BarCode; |
| 4 | +using Aspose.BarCode.Generation; |
4 | 5 | using Aspose.BarCode.BarCodeRecognition; |
| 6 | +using Aspose.Drawing; |
| 7 | +using Aspose.Drawing.Imaging; |
5 | 8 |
|
6 | | -namespace AsposeBarcodeS3Example |
| 9 | +class Program |
7 | 10 | { |
8 | | - class Program |
| 11 | + static void Main() |
9 | 12 | { |
10 | | - static void Main(string[] args) |
11 | | - { |
12 | | - // Path to the image file containing the PDF417 barcode. |
13 | | - // Replace with the actual path where the image is stored. |
14 | | - string localFilePath = "downloaded_image.png"; |
| 13 | + string imagePath = "sample_pdf417.png"; |
15 | 14 |
|
16 | | - if (!File.Exists(localFilePath)) |
| 15 | + if (!File.Exists(imagePath)) |
| 16 | + { |
| 17 | + using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Pdf417, "LINKED_SAMPLE_DATA")) |
17 | 18 | { |
18 | | - Console.WriteLine($"File not found: {localFilePath}"); |
19 | | - return; |
20 | | - } |
| 19 | + // Enable linked mode |
| 20 | + generator.Parameters.Barcode.Pdf417.IsLinked = true; |
21 | 21 |
|
22 | | - // Read PDF417 barcode and extract linked state metadata |
23 | | - try |
24 | | - { |
25 | | - using (BarCodeReader reader = new BarCodeReader(localFilePath, DecodeType.Pdf417)) |
| 22 | + // Add some macro metadata (optional, just for demonstration) |
| 23 | + generator.Parameters.Barcode.Pdf417.MacroPdf417FileID = 42; |
| 24 | + generator.Parameters.Barcode.Pdf417.MacroPdf417SegmentsCount = 1; |
| 25 | + generator.Parameters.Barcode.Pdf417.MacroPdf417SegmentID = 0; |
| 26 | + generator.Parameters.Barcode.Pdf417.MacroPdf417Addressee = "John Doe"; |
| 27 | + generator.Parameters.Barcode.Pdf417.MacroPdf417Sender = "Acme Corp"; |
| 28 | + |
| 29 | + using (Bitmap bitmap = generator.GenerateBarCodeImage()) |
26 | 30 | { |
27 | | - foreach (BarCodeResult result in reader.ReadBarCodes()) |
28 | | - { |
29 | | - Console.WriteLine("Barcode Type: " + result.CodeTypeName); |
30 | | - Console.WriteLine("Barcode Text: " + result.CodeText); |
31 | | - |
32 | | - // Access PDF417 extended parameters |
33 | | - if (result.Extended?.Pdf417 != null) |
34 | | - { |
35 | | - Console.WriteLine("IsLinked: " + result.Extended.Pdf417.IsLinked); |
36 | | - Console.WriteLine("IsCode128Emulation: " + result.Extended.Pdf417.IsCode128Emulation); |
37 | | - Console.WriteLine("MacroPdf417FileID: " + result.Extended.Pdf417.MacroPdf417FileID); |
38 | | - Console.WriteLine("MacroPdf417SegmentID: " + result.Extended.Pdf417.MacroPdf417SegmentID); |
39 | | - Console.WriteLine("MacroPdf417SegmentsCount: " + result.Extended.Pdf417.MacroPdf417SegmentsCount); |
40 | | - } |
41 | | - else |
42 | | - { |
43 | | - Console.WriteLine("No PDF417 extended parameters available."); |
44 | | - } |
45 | | - |
46 | | - Console.WriteLine(new string('-', 40)); |
47 | | - } |
| 31 | + bitmap.Save(imagePath, ImageFormat.Png); |
48 | 32 | } |
49 | 33 | } |
50 | | - catch (Exception ex) |
| 34 | + |
| 35 | + Console.WriteLine($"Sample barcode image generated at '{imagePath}'."); |
| 36 | + } |
| 37 | + |
| 38 | + if (!File.Exists(imagePath)) |
| 39 | + { |
| 40 | + Console.WriteLine($"Error: Image file '{imagePath}' not found."); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + using (BarCodeReader reader = new BarCodeReader(imagePath, DecodeType.Pdf417)) |
| 45 | + { |
| 46 | + foreach (BarCodeResult result in reader.ReadBarCodes()) |
51 | 47 | { |
52 | | - Console.WriteLine("Error during barcode recognition: " + ex.Message); |
| 48 | + Console.WriteLine($"Barcode Type : {result.CodeTypeName}"); |
| 49 | + Console.WriteLine($"Code Text : {result.CodeText}"); |
| 50 | + |
| 51 | + var pdf417 = result.Extended.Pdf417; |
| 52 | + Console.WriteLine($"IsLinked : {pdf417.IsLinked}"); |
| 53 | + Console.WriteLine($"IsCode128Emulation : {pdf417.IsCode128Emulation}"); |
| 54 | + Console.WriteLine($"IsReaderInitialization : {pdf417.IsReaderInitialization}"); |
| 55 | + Console.WriteLine($"MacroPdf417FileID : {pdf417.MacroPdf417FileID}"); |
| 56 | + Console.WriteLine($"MacroPdf417SegmentsCount : {pdf417.MacroPdf417SegmentsCount}"); |
| 57 | + Console.WriteLine($"MacroPdf417SegmentID : {pdf417.MacroPdf417SegmentID}"); |
| 58 | + Console.WriteLine($"MacroPdf417Addressee : {pdf417.MacroPdf417Addressee}"); |
| 59 | + Console.WriteLine($"MacroPdf417Sender : {pdf417.MacroPdf417Sender}"); |
| 60 | + Console.WriteLine($"MacroPdf417Terminator : {pdf417.MacroPdf417Terminator}"); |
| 61 | + Console.WriteLine($"MacroPdf417Checksum : {pdf417.MacroPdf417Checksum}"); |
| 62 | + Console.WriteLine($"MacroPdf417FileName : {pdf417.MacroPdf417FileName}"); |
| 63 | + Console.WriteLine($"MacroPdf417FileSize : {pdf417.MacroPdf417FileSize}"); |
| 64 | + Console.WriteLine($"MacroPdf417TimeStamp : {pdf417.MacroPdf417TimeStamp}"); |
| 65 | + Console.WriteLine(); |
53 | 66 | } |
54 | 67 | } |
55 | 68 | } |
|
0 commit comments