using IronBarCode;using IronSoftware.Drawing;using System.Collections.Generic;// Read barcode from PDF fileBarcodeResults result = BarcodeReader.ReadPdf("test.pdf");// Create list for barcodesList<AnyBitmap> barcodeList = new List<AnyBitmap>();foreach (BarcodeResult barcode in result){ barcodeList.Add(barcode.BarcodeImage);}// Create multi-page TIFFAnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif");
using IronBarCode;
using IronSoftware.Drawing;
using System.Collections.Generic;
// Read barcode from PDF file
BarcodeResults result = BarcodeReader.ReadPdf("test.pdf");
// Create list for barcodes
List<AnyBitmap> barcodeList = new List<AnyBitmap>();
foreach (BarcodeResult barcode in result)
{
barcodeList.Add(barcode.BarcodeImage);
}
// Create multi-page TIFF
AnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif");
ImportsIronBarCodeImportsIronSoftware.DrawingImportsSystem.Collections.Generic' Read barcode from PDF filePrivate result AsBarcodeResults = BarcodeReader.ReadPdf("test.pdf")' Create list for barcodesPrivate barcodeList As New List(OfAnyBitmap)()For Each barcode AsBarcodeResultIn result barcodeList.Add(barcode.BarcodeImage)Next barcode' Create multi-page TIFFAnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif")
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System.Collections.Generic
' Read barcode from PDF file
Private result As BarcodeResults = BarcodeReader.ReadPdf("test.pdf")
' Create list for barcodes
Private barcodeList As New List(Of AnyBitmap)()
For Each barcode As BarcodeResult In result
barcodeList.Add(barcode.BarcodeImage)
Next barcode
' Create multi-page TIFF
AnyBitmap.CreateMultiFrameTiff(barcodeList).SaveAs("barcodeImages.tif")
using IronBarCode;using System;// Read barcode from PNGBarcodeResults result = BarcodeReader.Read("bc3.png");// Output barcode type to consoleforeach (BarcodeResult barcode in result){Console.WriteLine("The barcode value is " + barcode.ToString() + " and the barcode type is " + barcode.BarcodeType);}
using IronBarCode;
using System;
// Read barcode from PNG
BarcodeResults result = BarcodeReader.Read("bc3.png");
// Output barcode type to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine("The barcode value is " + barcode.ToString() + " and the barcode type is " + barcode.BarcodeType);
}
ImportsIronBarCodeImportsSystem' Read barcode from PNGPrivate result AsBarcodeResults = BarcodeReader.Read("bc3.png")' Output barcode type to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine("The barcode value is " & barcode.ToString() & " and the barcode type is " & barcode.BarcodeType)Next barcode
Imports IronBarCode
Imports System
' Read barcode from PNG
Private result As BarcodeResults = BarcodeReader.Read("bc3.png")
' Output barcode type to console
For Each barcode As BarcodeResult In result
Console.WriteLine("The barcode value is " & barcode.ToString() & " and the barcode type is " & barcode.BarcodeType)
Next barcode
Using IronBarcode, users can retrieve the BARCODE value byte array by accessing the BinaryValue property of the BarcodeResult object. 這讓使用者能在程式內部進一步處理BARCODE value。 二進位 value 輸出在處理加密資料、以 BARCODE 編碼的檔案附件,或與需要位元組級資料處理的系統整合時,特別有用。
以下程式碼片段示範了將 BARCODE value 作為二進位資料擷取的其中一個應用案例:
using IronBarCode;// Read barcode from PNGBarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");int i = 1;foreach (BarcodeResult barcode in result){ var binaryValue = barcode.BinaryValue; var barcodeType = IronBarCode.BarcodeEncoding.QRCode; // Create QR code GeneratedBarcode generatedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType); // Export QR code generatedBarcode.SaveAsPng($"qrFromBinary{i}.png"); i++;}
using IronBarCode;
// Read barcode from PNG
BarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");
int i = 1;
foreach (BarcodeResult barcode in result)
{
var binaryValue = barcode.BinaryValue;
var barcodeType = IronBarCode.BarcodeEncoding.QRCode;
// Create QR code
GeneratedBarcode generatedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType);
// Export QR code
generatedBarcode.SaveAsPng($"qrFromBinary{i}.png");
i++;
}
ImportsIronBarCode' Read barcode from PNGPrivate result AsBarcodeResults = BarcodeReader.Read("multiple-barcodes.png")Private i AsInteger = 1For Each barcode AsBarcodeResultIn result Dim binaryValue = barcode.BinaryValue Dim barcodeType = IronBarCode.BarcodeEncoding.QRCode ' Create QR code Dim generatedBarcode AsGeneratedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType) ' Export QR code generatedBarcode.SaveAsPng($"qrFromBinary{i}.png") i += 1Next barcode
Imports IronBarCode
' Read barcode from PNG
Private result As BarcodeResults = BarcodeReader.Read("multiple-barcodes.png")
Private i As Integer = 1
For Each barcode As BarcodeResult In result
Dim binaryValue = barcode.BinaryValue
Dim barcodeType = IronBarCode.BarcodeEncoding.QRCode
' Create QR code
Dim generatedBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode(binaryValue, barcodeType)
' Export QR code
generatedBarcode.SaveAsPng($"qrFromBinary{i}.png")
i += 1
Next barcode
using IronBarCode;using IronSoftware.Drawing;using System.Linq;// Read barcode from PNGBarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");AnyBitmap bitmap = AnyBitmap.FromFile("multiple-barcodes.png");foreach (BarcodeResult barcode in result){ PointF[] barcodePoints = barcode.Points; float x1 = barcodePoints.Select(b => b.X).Min(); float y1 = barcodePoints.Select(b => b.Y).Min(); Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!); bitmap = bitmap.Redact(rectangle, Color.Magenta); // Save the image bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png);}
using IronBarCode;
using IronSoftware.Drawing;
using System.Linq;
// Read barcode from PNG
BarcodeResults result = BarcodeReader.Read("multiple-barcodes.png");
AnyBitmap bitmap = AnyBitmap.FromFile("multiple-barcodes.png");
foreach (BarcodeResult barcode in result)
{
PointF[] barcodePoints = barcode.Points;
float x1 = barcodePoints.Select(b => b.X).Min();
float y1 = barcodePoints.Select(b => b.Y).Min();
Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!);
bitmap = bitmap.Redact(rectangle, Color.Magenta);
// Save the image
bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png);
}
ImportsSystemImportsIronBarCodeImportsIronSoftware.DrawingImportsSystem.Linq' Read barcode from PNGPrivate result AsBarcodeResults = BarcodeReader.Read("multiple-barcodes.png")Private bitmap AsAnyBitmap = AnyBitmap.FromFile("multiple-barcodes.png")For Each barcode AsBarcodeResultIn result Dim barcodePoints() AsPointF = barcode.Points Dim x1 AsSingle = barcodePoints.Select(Function(b) b.X).Min() Dim y1 AsSingle = barcodePoints.Select(Function(b) b.Y).Min()'INSTANT VB TODO TASK: There is no VB equivalent to the C# 'null-forgiving operator':'ORIGINAL LINE: Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!); Dim rectangle As New Rectangle(CInt(Math.Truncate(x1)), CInt(Math.Truncate(y1)), CInt(barcode.Width), CInt(barcode.Height)) bitmap = bitmap.Redact(rectangle, Color.Magenta) ' Save the image bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png)Next barcode
Imports System
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System.Linq
' Read barcode from PNG
Private result As BarcodeResults = BarcodeReader.Read("multiple-barcodes.png")
Private bitmap As AnyBitmap = AnyBitmap.FromFile("multiple-barcodes.png")
For Each barcode As BarcodeResult In result
Dim barcodePoints() As PointF = barcode.Points
Dim x1 As Single = barcodePoints.Select(Function(b) b.X).Min()
Dim y1 As Single = barcodePoints.Select(Function(b) b.Y).Min()
'INSTANT VB TODO TASK: There is no VB equivalent to the C# 'null-forgiving operator':
'ORIGINAL LINE: Rectangle rectangle = new Rectangle((int)x1, (int)y1, (int)barcode.Width!, (int)barcode.Height!);
Dim rectangle As New Rectangle(CInt(Math.Truncate(x1)), CInt(Math.Truncate(y1)), CInt(barcode.Width), CInt(barcode.Height))
bitmap = bitmap.Redact(rectangle, Color.Magenta)
' Save the image
bitmap.SaveAs("redacted.png", AnyBitmap.ImageFormat.Png)
Next barcode
使用者可取得發現BarCode的頁碼。 對於使用包含多個BarCode的多頁文件,且需要了解文件中BarCode位置以便進行後續處理的使用者而言,這是一項實用的功能。 此功能對於從 PDF 文件讀取 BarCode,或在 Enterprise 應用程式中處理批次文件而言至關重要。
請參閱以下程式碼片段:
using IronBarCode;using System;// Read barcode from PDFBarcodeResults result = BarcodeReader.ReadPdf("test.pdf");// Output page number to consoleforeach (BarcodeResult barcode in result){Console.WriteLine("The barcode value " + barcode.ToString() + " is found on page number " + barcode.PageNumber);}
using IronBarCode;
using System;
// Read barcode from PDF
BarcodeResults result = BarcodeReader.ReadPdf("test.pdf");
// Output page number to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine("The barcode value " + barcode.ToString() + " is found on page number " + barcode.PageNumber);
}
ImportsIronBarCodeImportsSystem' Read barcode from PDFPrivate result AsBarcodeResults = BarcodeReader.ReadPdf("test.pdf")' Output page number to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine("The barcode value " & barcode.ToString() & " is found on page number " & barcode.PageNumber)Next barcode
Imports IronBarCode
Imports System
' Read barcode from PDF
Private result As BarcodeResults = BarcodeReader.ReadPdf("test.pdf")
' Output page number to console
For Each barcode As BarcodeResult In result
Console.WriteLine("The barcode value " & barcode.ToString() & " is found on page number " & barcode.PageNumber)
Next barcode
上方的程式碼片段展示了一個使用案例,其中使用者需要程式返回多頁 PDF 文件中發現的 BARCODE value 及其對應的頁碼。 該程式碼使用 BarcodeReader.ReadPdf() 方法讀取多頁 PDF 文件中的 BarCode,此方法會傳回 BarcodeResults 物件,其中儲存了文件中找到的每個 BarcodeResult。 我們使用迴圈遍歷物件中的每個項目,以擷取BARCODE的 value 以及發現BARCODE的頁碼。 除了此使用情境外,使用者亦可利用此屬性進行除錯,以確認文件中的所有BARCODE是否皆已讀取。
using IronBarCode;using System;// Read barcode from PDFBarcodeResults result = BarcodeReader.ReadPdf("test.pdf");// Output page orientation and rotation to consoleforeach (BarcodeResult barcode in result){Console.WriteLine(barcode.Value);Console.WriteLine(barcode.PageOrientation);Console.WriteLine(barcode.Rotation);}
using IronBarCode;
using System;
// Read barcode from PDF
BarcodeResults result = BarcodeReader.ReadPdf("test.pdf");
// Output page orientation and rotation to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine(barcode.Value);
Console.WriteLine(barcode.PageOrientation);
Console.WriteLine(barcode.Rotation);
}
ImportsIronBarCodeImportsSystem' Read barcode from PDFPrivate result AsBarcodeResults = BarcodeReader.ReadPdf("test.pdf")' Output page orientation and rotation to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine(barcode.Value)Console.WriteLine(barcode.PageOrientation)Console.WriteLine(barcode.Rotation)Next barcode
Imports IronBarCode
Imports System
' Read barcode from PDF
Private result As BarcodeResults = BarcodeReader.ReadPdf("test.pdf")
' Output page orientation and rotation to console
For Each barcode As BarcodeResult In result
Console.WriteLine(barcode.Value)
Console.WriteLine(barcode.PageOrientation)
Console.WriteLine(barcode.Rotation)
Next barcode
上方的程式碼片段已搭配附帶的範例 PDF 檔案執行,以證明使用者可透過分別取得 pageOrientation 和 BARCODE rotation,來檢索頁面方向與 BARCODE 旋轉角度。 此功能主要用於除錯。
using IronBarCode;using System;// Read barcode from PDFBarcodeResults result = BarcodeReader.ReadPdf("barcodestamped3.pdf");// Output text value to consoleforeach (BarcodeResult barcode in result){Console.WriteLine(barcode.Value);Console.WriteLine(barcode.Text);Console.WriteLine(barcode.ToString());}
using IronBarCode;
using System;
// Read barcode from PDF
BarcodeResults result = BarcodeReader.ReadPdf("barcodestamped3.pdf");
// Output text value to console
foreach (BarcodeResult barcode in result)
{
Console.WriteLine(barcode.Value);
Console.WriteLine(barcode.Text);
Console.WriteLine(barcode.ToString());
}
ImportsIronBarCodeImportsSystem' Read barcode from PDFPrivate result AsBarcodeResults = BarcodeReader.ReadPdf("barcodestamped3.pdf")' Output text value to consoleFor Each barcode AsBarcodeResultIn resultConsole.WriteLine(barcode.Value)Console.WriteLine(barcode.Text)Console.WriteLine(barcode.ToString())Next barcode
Imports IronBarCode
Imports System
' Read barcode from PDF
Private result As BarcodeResults = BarcodeReader.ReadPdf("barcodestamped3.pdf")
' Output text value to console
For Each barcode As BarcodeResult In result
Console.WriteLine(barcode.Value)
Console.WriteLine(barcode.Text)
Console.WriteLine(barcode.ToString())
Next barcode
從上方的程式碼片段可見,使用者只需幾行程式碼,即可透過 IronBarcode 讀取圖片中的 BARCODE。 在遍歷 BarcodeResults 方法所傳回的 BarcodeReader.Read() 後,我們將取得 Value 和 Text 屬性的結果,並呼叫 BarcodeResult.ToString() 方法,以展示所有這些操作皆會返回相同的 value。
What kind of applications benefit from using IronBarcode's output data formats?
Applications in inventory management, document processing, and quality control greatly benefit from IronBarcode's diverse data formats as they offer extensive barcode data processing options.
Can IronBarcode read barcodes from multipage PDF documents?
Yes, IronBarcode can read barcodes from multipage PDF documents using methods like `BarcodeReader.ReadPdf()`, which also informs about the page number on which each barcode is found.