跳至頁尾內容
影片

如何在C#中自定義和新增標志以QR碼 | IronBarcode

從Syncfusion Barcode遷移到IronBarcode

本指南提供了從Syncfusion的條碼控件——SfBarcodeGenerator(適用於Blazor和MAUI)遷移到IronBarcode的完整路徑。 它涵蓋了團隊進行此轉換的結構性原因,替換NuGet包和授權設置的分步快速啟動,每個常見場景的完整前後程式碼範例,以及為審計現有程式碼庫而設的遷移檢查清單。 如果項目還使用其他Syncfusion組件(如網格、圖表、排程器),則那些包及其註冊不受影響——僅更改條碼相關程式碼。

為何從Syncfusion Barcode遷移

閱讀缺口: SfBarcodeGenerator是生成控件,沒有閱讀能力。 兩個類中都沒有.Scan()方法。 當項目需要從上傳的圖像、掃描文件或PDF文件中讀取條碼時,Syncfusion的條碼控件沒有提供解決方案。 Syncfusion的文件指導團隊使用Barcode Reader OPX作為解決方案,這是一個需要單獨購買、授權並獨立維護的商業產品。

OPX作為免費軟體的付費外包: Barcode Reader OPX內部使用ZXing.Net——一個根據Apache 2.0許可發布的開源條碼讀取庫。 Apache 2.0是一個寬鬆的許可; 任何.NET開發者都可以直接使用dotnet add package ZXing.Net安裝ZXing.Net,並在商業應用中免費使用。完整的Syncfusion讀取和生成工作流程需要兩個獨立的Syncfusion產品、兩個授權協議和兩個API表面,而閱讀能力本可以直接來自OPX包裝的免費庫。

社區許可崖: Syncfusion的社區許可要求同時且持續滿足四個條件: 年收入低於$1,000,000,開發者不超過五名,員工總數不超過十名,總外部資金籌集低於$3,000,000。不論規模大小,政府組織均不符合條件。超過任意一項條件都會立即觸發商業授權義務。 一輪A輪融資通常會在其完成的當天將所籌資金推過$3,000,000的門檻,從而觸發一個授權費,無論團隊大小或收入如何。 商業過渡從$0變成每位開發者年度Essential Studio訂閱——該訂閱涵蓋整個套件,而不僅僅是條碼組件。 Syncfusion公布的路徑是銷售的自定義報價。

版本特定的密鑰輪換: Syncfusion的密鑰是綁定在特定Essential Studio版本範圍上的。 從版本24.x升級到25.x需要從帳戶門戶獲得新的密鑰,在每個部署環境的密鑰儲存中更新該密鑰,並進行重新部署以防止試用水印出現在生產輸出中。 對於具有頻繁發佈節奏或多個部署目標的團隊來說,這種輪換變成了持續且不成比例的操作負擔,相對於生成條碼圖像的基本需求。

基本問題

Syncfusion的控件架構使得程式化文件生成間接化。 使用DrawToBitmap,然後保存位圖——一種攜帶Windows Forms運行時作為依賴項的WinForms渲染模式:

//SyncfusionSfBarcode: indirect file output through DrawToBitmap
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY");

var barcode = new SfBarcode();
barcode.Text = "SHIP-2024-001";
barcode.Symbology = BarcodeSymbolType.Code128A;
barcode.Width = 400;
barcode.Height = 150;

using var bitmap = new Bitmap(barcode.Width, barcode.Height);
barcode.DrawToBitmap(bitmap, barcode.ClientRectangle);
bitmap.Save("shipping-label.png", ImageFormat.Png);
// Reading: not possible — requires separate OPX purchase
//SyncfusionSfBarcode: indirect file output through DrawToBitmap
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY");

var barcode = new SfBarcode();
barcode.Text = "SHIP-2024-001";
barcode.Symbology = BarcodeSymbolType.Code128A;
barcode.Width = 400;
barcode.Height = 150;

using var bitmap = new Bitmap(barcode.Width, barcode.Height);
barcode.DrawToBitmap(bitmap, barcode.ClientRectangle);
bitmap.Save("shipping-label.png", ImageFormat.Png);
// Reading: not possible — requires separate OPX purchase
Imports Syncfusion.Licensing
Imports System.Drawing
Imports System.Drawing.Imaging

' SyncfusionSfBarcode: indirect file output through DrawToBitmap
SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY")

Dim barcode As New SfBarcode()
barcode.Text = "SHIP-2024-001"
barcode.Symbology = BarcodeSymbolType.Code128A
barcode.Width = 400
barcode.Height = 150

Using bitmap As New Bitmap(barcode.Width, barcode.Height)
    barcode.DrawToBitmap(bitmap, barcode.ClientRectangle)
    bitmap.Save("shipping-label.png", ImageFormat.Png)
End Using
' Reading: not possible — requires separate OPX purchase
$vbLabelText   $csharpLabel

IronBarcode直接生成文件,並使用相同的包進行讀取:

// IronBarcode: direct generation and reading in one package
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

// Generate
BarcodeWriter.CreateBarcode("SHIP-2024-001", BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .SaveAsPng("shipping-label.png");

// Read — same package, no additional product required
var results = BarcodeReader.Read("shipping-label.png");
foreach (var result in results)
    Console.WriteLine($"{result.Format}: {result.Value}");
// IronBarcode: direct generation and reading in one package
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

// Generate
BarcodeWriter.CreateBarcode("SHIP-2024-001", BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .SaveAsPng("shipping-label.png");

// Read — same package, no additional product required
var results = BarcodeReader.Read("shipping-label.png");
foreach (var result in results)
    Console.WriteLine($"{result.Format}: {result.Value}");
Imports IronBarCode

' IronBarcode: direct generation and reading in one package
License.LicenseKey = "YOUR-LICENSE-KEY"

' Generate
BarcodeWriter.CreateBarcode("SHIP-2024-001", BarcodeEncoding.Code128) _
    .ResizeTo(400, 150) _
    .SaveAsPng("shipping-label.png")

' Read — same package, no additional product required
Dim results = BarcodeReader.Read("shipping-label.png")
For Each result In results
    Console.WriteLine($"{result.Format}: {result.Value}")
Next
$vbLabelText   $csharpLabel

IronBarcode與Syncfusion Barcode:功能對比

功能 Syncfusion Barcode IronBarcode
條碼生成 是的——UI控件(WinForms,WPF,Blazor,MAUI) 是的——靜態API,所有環境
條碼讀取 否——需要單獨的Barcode Reader OPX 是的——同一個包
OPX閱讀產品包裝ZXing.Net(Apache 2.0) 不適用
PDF條碼輸出 否——需要附加Syncfusion.Pdf 是的——內建SaveAsPdf()
PDF 條碼讀取 是——原生
伺服器端/無頭生成 需要WinForms運行時(DrawToBitmap 本地化——沒有UI依賴項
Docker / Linux部署 有限 完全支援
ASP.NET Core最小API 不直接支援 完全支援
內嵌logo的QR碼 是的——.AddBrandLogo()
讀取時自動格式檢測 不適用
社區/免費等級 社區許可(四個同時條件) 30天試用(僅水印)
商業許可模式 年度訂閱(Essential Studio) 永久(一時間,見ironsoftware.com/csharp/barcode/licensing)
授權密鑰範圍 版本特定,隨著主要NuGet更新而輪換 版本穩定在主要版本中
平臺註冊步驟 3–4 steps (RegisterLicense + AddSyncfusionBlazor + ConfigureSyncfusionCore + razor imports) 一行,所有平臺
1D格式範圍 Code 128,Code 39,EAN,UPC,Codabar及其他 所有Syncfusion格式外加PDF417,Aztec,MaxiCode,GS1,USPS IMb及50+
2D格式範圍 QR Code,DataMatrix QR Code,DataMatrix,PDF417,Micro PDF417,Aztec,MaxiCode

快速開始

步驟1:替換NuGet包

移除使用中的平臺的Syncfusion條碼包。 如果項目目標面向多個平台,則對每個平台都運行移除。

# Blazor
dotnet remove package Syncfusion.Blazor.BarcodeGenerator

# WinForms
dotnet remove package Syncfusion.SfBarcode.Windows

# WPF
dotnet remove package Syncfusion.SfBarcode.WPF

# MAUI
dotnet remove package Syncfusion.Maui.Barcode
# Blazor
dotnet remove package Syncfusion.Blazor.BarcodeGenerator

# WinForms
dotnet remove package Syncfusion.SfBarcode.Windows

# WPF
dotnet remove package Syncfusion.SfBarcode.WPF

# MAUI
dotnet remove package Syncfusion.Maui.Barcode
SHELL

如果在移除條碼包後,項目中沒有其他Syncfusion包,則也移除授權包:

dotnet remove package Syncfusion.Licensing
dotnet remove package Syncfusion.Licensing
SHELL

安裝IronBarcode——所有平臺用一個包:

dotnet add package IronBarcode
dotnet add package IronBarcode
SHELL

步驟 2:更新命名空間

移除Syncfusion條碼命名空間並新增IronBarcode命名空間:

// Remove these (barcode-specific; leave others if non-barcodeSyncfusioncontrols remain)
using Syncfusion.Windows.Forms.Barcode;
using Syncfusion.Licensing;
// @using Syncfusion.Blazor.BarcodeGenerator  (in _Imports.razor)

// Add this
using IronBarCode;
// Remove these (barcode-specific; leave others if non-barcodeSyncfusioncontrols remain)
using Syncfusion.Windows.Forms.Barcode;
using Syncfusion.Licensing;
// @using Syncfusion.Blazor.BarcodeGenerator  (in _Imports.razor)

// Add this
using IronBarCode;
Imports IronBarCode
$vbLabelText   $csharpLabel

步驟 3:初始化授權

移除應用程式啟動中的Syncfusion授權註冊和平臺配置。然後在相同的啟動位置新增一行IronBarcode授權行:

// Remove from Program.cs / App.xaml.cs / MauiProgram.cs:
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY");
builder.Services.AddSyncfusionBlazor();         // Blazor only — remove if no otherSyncfusioncontrols
builder.ConfigureSyncfusionCore();              // MAUI only — remove if no otherSyncfusioncontrols

// Add at the same startup point:
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// Remove from Program.cs / App.xaml.cs / MauiProgram.cs:
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY");
builder.Services.AddSyncfusionBlazor();         // Blazor only — remove if no otherSyncfusioncontrols
builder.ConfigureSyncfusionCore();              // MAUI only — remove if no otherSyncfusioncontrols

// Add at the same startup point:
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
' Remove from Program.vb / App.xaml.vb / MauiProgram.vb:
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY")
builder.Services.AddSyncfusionBlazor()         ' Blazor only — remove if no other Syncfusion controls
builder.ConfigureSyncfusionCore()              ' MAUI only — remove if no other Syncfusion controls

' Add at the same startup point:
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

對於CI/CD流程和Docker容器,將密鑰儲存在環境變數中:

IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE");
IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE");
Imports System

IronBarCode.License.LicenseKey = Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE")
$vbLabelText   $csharpLabel

程式碼遷移範例

WinForms SfBarcode to BarcodeWriter

WinForms遷移消除了DrawToBitmap間接,並將其替換為直接的文件輸出鏈。 Syncfusion模式需要預分配一個已知尺寸的Bitmap; IronBarcode作為生成調用的一部分計算尺寸。

Syncfusion方法:

using Syncfusion.Windows.Forms.Barcode;
using System.Drawing;
using System.Drawing.Imaging;

Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY");

var barcode = new SfBarcode();
barcode.Text = "ORD-20240315-001";
barcode.Symbology = BarcodeSymbolType.Code128A;
barcode.BarHeight = 100;
barcode.NarrowBarWidth = 1;
barcode.ShowText = true;
barcode.Width = 400;
barcode.Height = 150;

using var bitmap = new Bitmap(barcode.Width, barcode.Height);
barcode.DrawToBitmap(bitmap, barcode.ClientRectangle);
bitmap.Save("order-label.png", ImageFormat.Png);
using Syncfusion.Windows.Forms.Barcode;
using System.Drawing;
using System.Drawing.Imaging;

Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY");

var barcode = new SfBarcode();
barcode.Text = "ORD-20240315-001";
barcode.Symbology = BarcodeSymbolType.Code128A;
barcode.BarHeight = 100;
barcode.NarrowBarWidth = 1;
barcode.ShowText = true;
barcode.Width = 400;
barcode.Height = 150;

using var bitmap = new Bitmap(barcode.Width, barcode.Height);
barcode.DrawToBitmap(bitmap, barcode.ClientRectangle);
bitmap.Save("order-label.png", ImageFormat.Png);
Imports Syncfusion.Windows.Forms.Barcode
Imports System.Drawing
Imports System.Drawing.Imaging

Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR-VERSION-SPECIFIC-KEY")

Dim barcode As New SfBarcode()
barcode.Text = "ORD-20240315-001"
barcode.Symbology = BarcodeSymbolType.Code128A
barcode.BarHeight = 100
barcode.NarrowBarWidth = 1
barcode.ShowText = True
barcode.Width = 400
barcode.Height = 150

Using bitmap As New Bitmap(barcode.Width, barcode.Height)
    barcode.DrawToBitmap(bitmap, barcode.ClientRectangle)
    bitmap.Save("order-label.png", ImageFormat.Png)
End Using
$vbLabelText   $csharpLabel

IronBarcode 方法:

using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

BarcodeWriter.CreateBarcode("ORD-20240315-001", BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .AddBarcodeText()
    .SaveAsPng("order-label.png");
using IronBarCode;

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";

BarcodeWriter.CreateBarcode("ORD-20240315-001", BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .AddBarcodeText()
    .SaveAsPng("order-label.png");
Imports IronBarCode

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"

BarcodeWriter.CreateBarcode("ORD-20240315-001", BarcodeEncoding.Code128) _
    .ResizeTo(400, 150) _
    .AddBarcodeText() _
    .SaveAsPng("order-label.png")
$vbLabelText   $csharpLabel

BarcodeSymbolType.Code128A 映射到 BarcodeEncoding.Code128DrawToBitmap + Bitmap.Save 序列合併為 .SaveAsPng()。 如果條碼必須顯示在WinForms .ToPngBinaryData()將圖像載入到控件中。 IronBarcode中包含的1D條碼格式範圍遠超Syncfusion控件支持的列表。

Blazor SfBarcodeGenerator到最小API端點

Blazor遷移是一種結構性變更,而不是逐行替換。 SfBarcodeGenerator是一個Razor組件,通過Syncfusion的JavaScript層在瀏覽器中渲染。 IronBarcode沒有Razor組件; 它是伺服器端程式庫。 替換模式是在伺服器上生成一個最小API端點,返回條碼字節,在Razor頁面中被引用為圖像來源。

Syncfusion方法:

@page "/fulfillment"
@using Syncfusion.Blazor.BarcodeGenerator

<SfBarcodeGenerator
    Width="300px"
    Height="150px"
    Type="BarcodeType.Code128"
    Value="@orderNumber">
    <BarcodeGeneratorDisplayText Visibility="true"></BarcodeGeneratorDisplayText>
</SfBarcodeGenerator>

@code {
    private string orderNumber = "ORD-20240315-001";
}

IronBarcode 方法:

Program.cs中新增一個生成端點:

using IronBarCode;

app.MapGet("/barcode/{value}", (string value) =>
{
    var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
        .ResizeTo(300, 150)
        .AddBarcodeText()
        .ToPngBinaryData();

    return Results.File(bytes, "image/png");
});
using IronBarCode;

app.MapGet("/barcode/{value}", (string value) =>
{
    var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
        .ResizeTo(300, 150)
        .AddBarcodeText()
        .ToPngBinaryData();

    return Results.File(bytes, "image/png");
});
Imports IronBarCode

app.MapGet("/barcode/{value}", Function(value As String)
    Dim bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128) _
        .ResizeTo(300, 150) _
        .AddBarcodeText() _
        .ToPngBinaryData()

    Return Results.File(bytes, "image/png")
End Function)
$vbLabelText   $csharpLabel

在Razor組件中引用這個端點:

@page "/fulfillment"

<img src="/barcode/@orderNumber" alt="Order barcode: @orderNumber" />

@code {
    private string orderNumber = "ORD-20240315-001";
}

此端點可獨立測試,並可從任何HTTP客戶端重複使用,並且相容於Blazor Server,Blazor WebAssembly與託管API後端,及任何其他網頁前端。

QR 碼生成

Syncfusion的QR組件也在瀏覽器中渲染,沒有伺服器端輸出路徑。 IronBarcode在伺服器端生成QR碼,並直接輸出文件。

Syncfusion方法:

@using Syncfusion.Blazor.BarcodeGenerator

<SfQRCodeGenerator
    Width="300px"
    Height="300px"
    Value="https://example.com/product/ABC-123">
    <QRCodeGeneratorDisplayText Visibility="false">
    </QRCodeGeneratorDisplayText>
</SfQRCodeGenerator>

IronBarcode 方法:

using IronBarCode;

// Standard QR code
QRCodeWriter.CreateQrCode("https://example.com/product/ABC-123", 300,
    QRCodeWriter.QrErrorCorrectionLevel.High)
    .SaveAsPng("product-qr.png");

// QR code with embedded brand logo — not available in Syncfusion
QRCodeWriter.CreateQrCode("https://example.com/product/ABC-123", 500,
    QRCodeWriter.QrErrorCorrectionLevel.Highest)
    .AddBrandLogo("company-logo.png")
    .SaveAsPng("product-qr-branded.png");
using IronBarCode;

// Standard QR code
QRCodeWriter.CreateQrCode("https://example.com/product/ABC-123", 300,
    QRCodeWriter.QrErrorCorrectionLevel.High)
    .SaveAsPng("product-qr.png");

// QR code with embedded brand logo — not available in Syncfusion
QRCodeWriter.CreateQrCode("https://example.com/product/ABC-123", 500,
    QRCodeWriter.QrErrorCorrectionLevel.Highest)
    .AddBrandLogo("company-logo.png")
    .SaveAsPng("product-qr-branded.png");
Imports IronBarCode

' Standard QR code
QRCodeWriter.CreateQrCode("https://example.com/product/ABC-123", 300, QRCodeWriter.QrErrorCorrectionLevel.High) _
    .SaveAsPng("product-qr.png")

' QR code with embedded brand logo — not available in Syncfusion
QRCodeWriter.CreateQrCode("https://example.com/product/ABC-123", 500, QRCodeWriter.QrErrorCorrectionLevel.Highest) _
    .AddBrandLogo("company-logo.png") _
    .SaveAsPng("product-qr-branded.png")
$vbLabelText   $csharpLabel

OPX讀取替代方案

如果項目使用了Barcode Reader OPX——或將讀取需求推遲到未來的OPX購買,IronBarcode可以用已安裝的包取代這個依賴。 沒有第二產品,沒有第二個授權。

Syncfusion方法(Barcode Reader OPX):

// Requires separateSyncfusion BarcodeReader OPX purchase
// OPX wraps ZXing.Net internally (Apache 2.0 — free to use directly)
using Syncfusion.BarcodeReader;

var reader = new BarcodeReader();
var results = reader.ReadBarcodes("warehouse-scan.png");
foreach (var result in results)
    Console.WriteLine($"Value: {result.Value}");
// Requires separateSyncfusion BarcodeReader OPX purchase
// OPX wraps ZXing.Net internally (Apache 2.0 — free to use directly)
using Syncfusion.BarcodeReader;

var reader = new BarcodeReader();
var results = reader.ReadBarcodes("warehouse-scan.png");
foreach (var result in results)
    Console.WriteLine($"Value: {result.Value}");
Imports Syncfusion.BarcodeReader

Dim reader As New BarcodeReader()
Dim results = reader.ReadBarcodes("warehouse-scan.png")
For Each result In results
    Console.WriteLine($"Value: {result.Value}")
Next
$vbLabelText   $csharpLabel

IronBarcode 方法:

using IronBarCode;

// Included in the same NuGet package as generation — no second product required
var results = BarcodeReader.Read("warehouse-scan.png");
foreach (var result in results)
{
    Console.WriteLine($"Format: {result.Format}");
    Console.WriteLine($"Value: {result.Value}");
    Console.WriteLine($"Confidence: {result.Confidence}%");
}
using IronBarCode;

// Included in the same NuGet package as generation — no second product required
var results = BarcodeReader.Read("warehouse-scan.png");
foreach (var result in results)
{
    Console.WriteLine($"Format: {result.Format}");
    Console.WriteLine($"Value: {result.Value}");
    Console.WriteLine($"Confidence: {result.Confidence}%");
}
Imports IronBarCode

' Included in the same NuGet package as generation — no second product required
Dim results = BarcodeReader.Read("warehouse-scan.png")
For Each result In results
    Console.WriteLine($"Format: {result.Format}")
    Console.WriteLine($"Value: {result.Value}")
    Console.WriteLine($"Confidence: {result.Confidence}%")
Next
$vbLabelText   $csharpLabel

條碼讀取文件涵蓋了對於上傳處理器的字節陣列進行讀取、速度與準確性的調整以及多條碼探測。

PDF條碼生成

Syncfusion條碼控件沒有PDF輸出路徑。 IronBarcode將PDF視為一個一等輸出格式。

Syncfusion方法:

//否direct path — requires combining Syncfusion.Barcode.WinForms and Syncfusion.Pdf
// Step 1: Generate to Bitmap via DrawToBitmap
// Step 2: LoadSyncfusionPDF document
// Step 3: Insert bitmap as image element
// Two packages, two APIs, two license obligations
//否direct path — requires combining Syncfusion.Barcode.WinForms and Syncfusion.Pdf
// Step 1: Generate to Bitmap via DrawToBitmap
// Step 2: LoadSyncfusionPDF document
// Step 3: Insert bitmap as image element
// Two packages, two APIs, two license obligations
'否direct path — requires combining Syncfusion.Barcode.WinForms and Syncfusion.Pdf
' Step 1: Generate to Bitmap via DrawToBitmap
' Step 2: LoadSyncfusionPDF document
' Step 3: Insert bitmap as image element
' Two packages, two APIs, two license obligations
$vbLabelText   $csharpLabel

IronBarcode 方法:

using IronBarCode;

// Generate directly to PDF — no secondary library required
BarcodeWriter.CreateBarcode("PALLET-2024-0891", BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .SaveAsPdf("pallet-label.pdf");

// Read barcodes from an existing PDF
var pdfResults = BarcodeReader.Read("shipping-manifest.pdf");
foreach (var result in pdfResults)
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}");
using IronBarCode;

// Generate directly to PDF — no secondary library required
BarcodeWriter.CreateBarcode("PALLET-2024-0891", BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .SaveAsPdf("pallet-label.pdf");

// Read barcodes from an existing PDF
var pdfResults = BarcodeReader.Read("shipping-manifest.pdf");
foreach (var result in pdfResults)
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}");
Imports IronBarCode

' Generate directly to PDF — no secondary library required
BarcodeWriter.CreateBarcode("PALLET-2024-0891", BarcodeEncoding.Code128) _
    .ResizeTo(400, 150) _
    .SaveAsPdf("pallet-label.pdf")

' Read barcodes from an existing PDF
Dim pdfResults = BarcodeReader.Read("shipping-manifest.pdf")
For Each result In pdfResults
    Console.WriteLine($"Page {result.PageNumber}: {result.Value}")
Next
$vbLabelText   $csharpLabel

條碼PDF生成指南涵蓋了多頁PDF輸出並將條碼嵌入到其他文件內容旁邊。

Syncfusion條碼API到IronBarcode的映射參考

Syncfusion IronBarcode
SyncfusionLicenseProvider.RegisterLicense("KEY") IronBarCode.License.LicenseKey = "key"
builder.Services.AddSyncfusionBlazor() 不需要
builder.ConfigureSyncfusionCore() 不需要
new SfBarcode() BarcodeWriter.CreateBarcode()(靜態)
barcode.Text = "value" CreateBarcode()的第一個參數
barcode.Symbology = BarcodeSymbolType.Code128A BarcodeEncoding.Code128
barcode.Symbology = BarcodeSymbolType.QRBarcode QRCodeWriter.CreateQrCode()
barcode.BarHeight = 100 .ResizeTo(width, 100)
barcode.ShowText = true .AddBarcodeText()
barcode.DrawToBitmap(bitmap, rect) .SaveAsPng(path)
手動BitmapMemoryStream .ToPngBinaryData()
<SfBarcodeGenerator Type="BarcodeType.Code128" Value="..."> API端點中的BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
<SfQRCodeGenerator Value="..."> API端點中的QRCodeWriter.CreateQrCode(value, size)
BarcodeType.Code128(Blazor枚舉) BarcodeEncoding.Code128
Barcode Reader OPX(單獨產品,包裝ZXing.Net) BarcodeReader.Read(path) — 本地化,同一個包
控件中沒有讀取API BarcodeReader.Read(path)
控件中沒有PDF輸出 .SaveAsPdf(path)
沒有PDF讀取 BarcodeReader.Read("document.pdf")

常見遷移問題及解決方案

問題1:NuGet更新後的試用水印

Syncfusion:從Essential Studio 24.x升級到25.x將使現有授權密鑰失效。 在更新密鑰儲存之前生成的任何輸出將顯示試用水印。 這是一個靜默失敗——應用程式繼續運行,但會產生不符合規範的輸出。

解決方案:在更新IronBarcode NuGet包之後,授權密鑰在主要版本中的小版本中不會改變。 對於小版本或補丁釋放,不需要更新密鑰或重新部署。 升級到新的主要版本時,在應用程式入口處更新一次密鑰:

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
Imports IronBarCode

IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
$vbLabelText   $csharpLabel

問題2:DrawToBitmap在無頭環境中失敗

Syncfusion: SfBarcode.DrawToBitmap依賴於Windows Forms渲染管道。在ASP.NET Core進程、Azure函式或Linux Docker容器中,調用InvalidOperationException或生成空白位圖,因為沒有Windows Forms消息迴圈。

解決方案:BarcodeWriter.CreateBarcode()替代。 IronBarcode在無任何UI運行時依賴的情況下在受控程式碼中執行生成:

// Works in ASP.NET Core, Azure Functions, Docker on Linux, console apps
var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .ToPngBinaryData();
// Works in ASP.NET Core, Azure Functions, Docker on Linux, console apps
var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
    .ResizeTo(400, 150)
    .ToPngBinaryData();
' Works in ASP.NET Core, Azure Functions, Docker on Linux, console apps
Dim bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128) _
    .ResizeTo(400, 150) _
    .ToPngBinaryData()
$vbLabelText   $csharpLabel

問題3:SfBarcodeGenerator沒有伺服器端輸出

Syncfusion: SfBarcodeGenerator是一個Razor組件,沒有伺服器端API表面。 嘗試在控制器行動或後臺服務中使用它時,找不到適用於生成條碼字節的方法。

解決方案:建立一個最小API端點,在伺服器端生成條碼,並將其作為HTTP響應返回。 通過<img src="...">標籤從Razor組件中引用該端點:

app.MapGet("/barcode/{value}", (string value) =>
{
    var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
        .ResizeTo(300, 150)
        .ToPngBinaryData();
    return Results.File(bytes, "image/png");
});
app.MapGet("/barcode/{value}", (string value) =>
{
    var bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128)
        .ResizeTo(300, 150)
        .ToPngBinaryData();
    return Results.File(bytes, "image/png");
});
Imports Microsoft.AspNetCore.Builder
Imports Microsoft.AspNetCore.Http

app.MapGet("/barcode/{value}", Function(value As String)
                                   Dim bytes = BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128) _
                                       .ResizeTo(300, 150) _
                                       .ToPngBinaryData()
                                   Return Results.File(bytes, "image/png")
                               End Function)
$vbLabelText   $csharpLabel

問題4:缺少閱讀能力(未購買OPX)

Syncfusion:由於尚未購買OPX而延遲條碼閱讀的項目沒有閱讀程式碼可供遷移。 從頭新增閱讀能力需要OPX購買、整合和一個新的授權協議。

解決方案: IronBarcode閱讀功能包含在同一個包中。 不需要採購或第二個授權。 在需要閱讀的地方新增BarcodeReader.Read(path)

var results = BarcodeReader.Read("incoming-scan.png");
var results = BarcodeReader.Read("incoming-scan.png");
Dim results = BarcodeReader.Read("incoming-scan.png")
$vbLabelText   $csharpLabel

問題5:遷移中的社區許可過期

Syncfusion:在遷移窗口期間超過任何資格門檻(包括完成一輪資金籌集)的團隊可能會發現Syncfusion控件在遷移完成之前停止生成有效輸出。

解決方案: IronBarcode的30天試用允許在沒有收入、員工數或資金條件的情況下進行完整評估。 試用水印會出現在生成的輸出上; 啟用購買的授權密鑰可將其移除。 IronBarcode的許可模式中沒有組織規模的門檻。

Syncfusion條碼遷移檢查清單

遷移前任務

審計程式碼庫以找到每個引用Syncfusion條碼的文件:

grep -r "SyncfusionLicenseProvider.RegisterLicense\|AddSyncfusionBlazor\|ConfigureSyncfusionCore" --include="*.cs" .
grep -r "new SfBarcode\(\)\|SfBarcodeGenerator\|SfQRCodeGenerator" --include="*.cs" --include="*.razor" .
grep -r "BarcodeSymbolType\.\|BarcodeType\." --include="*.cs" --include="*.razor" .
grep -r "DrawToBitmap\|barcode\.Text\s*=" --include="*.cs" .
grep -r "Syncfusion\.Barcode\|Syncfusion\.Blazor\.BarcodeGenerator" --include="*.csproj" .
grep -r "SyncfusionLicenseProvider.RegisterLicense\|AddSyncfusionBlazor\|ConfigureSyncfusionCore" --include="*.cs" .
grep -r "new SfBarcode\(\)\|SfBarcodeGenerator\|SfQRCodeGenerator" --include="*.cs" --include="*.razor" .
grep -r "BarcodeSymbolType\.\|BarcodeType\." --include="*.cs" --include="*.razor" .
grep -r "DrawToBitmap\|barcode\.Text\s*=" --include="*.cs" .
grep -r "Syncfusion\.Barcode\|Syncfusion\.Blazor\.BarcodeGenerator" --include="*.csproj" .
SHELL

在編寫任何遷移程式碼之前記錄以下內容:

  • 列出每個調用SyncfusionLicenseProvider.RegisterLicense的文件
  • 列出每個SfBarcode的實例化及其屬性賦值
  • 列出每個<SfQRCodeGenerator> Razor組件的使用
  • 列出每一個DrawToBitmap調用及其下游的保存或顯示路徑
  • 確認是否安裝了Barcode Reader OPX; 如果是,列出每個閱讀調用

程式碼更新任務

  1. 移除每個平台中的Syncfusion條碼NuGet包
  2. 如果沒有其他Syncfusion控件留存,刪除Syncfusion.Licensing NuGet包
  3. 安裝IronBarcode NuGet包
  4. 在程式入口處用SyncfusionLicenseProvider.RegisterLicense("KEY")
  5. 如果沒有其他Syncfusion控件留存,移除builder.Services.AddSyncfusionBlazor()
  6. 如果沒有其他Syncfusion控件留存,移除builder.ConfigureSyncfusionCore()
  7. 如果適用,從@using Syncfusion.Blazor.BarcodeGenerator
  8. using Syncfusion.Licensing
  9. new SfBarcode() +屬性賦值+DrawToBitmap
  10. BarcodeSymbolType.Code128A(及同等)
  11. 將每個BarcodeEncoding.Code128
  12. 用最小API端點和一個<img src="..."> 參考替換每個<SfBarcodeGenerator> Razor組件
  13. 用一個QRCodeWriter.CreateQrCode() 端點和一個<img src="..."> 參考替換每個<SfQRCodeGenerator> Razor組件
  14. BarcodeReader.Read(path)替換所有Barcode Reader OPX閱讀調用
  15. 在由於未購買OPX,之前缺乏閱讀能力的地方新增BarcodeReader.Read(path)

遷移後測試

  • 用硬體掃描器或參考閱讀應用程式驗證生成的條碼圖像的掃描有效性
  • 授權密鑰啟用後確認生成的輸出上沒有出現試用水印
  • 確認BarcodeReader.Read() 返回的值和格式對於使用中的每個條碼型別是預期的
  • .SaveAsPdf()測試PDF輸出,以確認頁面尺寸和條碼尺寸符合設計要求
  • 在Razor組件中測試之前,直接測試Blazor最小API端點(通過瀏覽器或HTTP客戶端)
  • 確認Docker和Linux部署生成的輸出與Windows開發機器相同
  • 進行最終的SyncfusionLicenseProvider的引用

遷移到IronBarcode的主要優勢

統一生成和閱讀:遷移後,生成和閱讀都通過單一的NuGet包在一個授權下運行。 不需要購買第二產品,不需要學習第二API表面,也不需要消耗授權預算於ZXing.Net包裝依賴而該預算本可用於直接的開源庫。

消除版本特定的密鑰輪換:IronBarcode的許可密鑰在小版本和補丁更新中保持有效。 獲取新密鑰、更新每個部署環境中的密鑰儲存、並為每一個主要NuGet版本更新而重新部署以清除試用水印的操作負擔徹底消除。

平臺獨立部署:相同的IronBarcode包和相同的生成API在WinForms桌面、ASP.NET Core服務、Azure Functions、控制台應用程式和Linux Docker容器中運行。 透過DrawToBitmap引入的Windows Forms運行時依賴被移除,Blazor部署從瀏覽器渲染組件轉移到獨立可測試且客戶端無關的伺服器端API端點。

原生PDF支持:生成和閱讀均原生延伸到PDF。 生成條碼PDF不再需要協調兩個Syncfusion產品; 從PDF清單和裝運文件中讀取條碼不再需要單獨的PDF提取步驟。

可預見的許可經濟學: IronBarcode的永久許可模式不強加收入、員工數、或資本門檻。 達到Syncfusion社區許可資格條件的團隊——或預期將達到的——轉向一個授權模式,而組織的增長不會產生合規事件。

請注意Syncfusion和ZXing.NET是其各自所有者的註冊商標。 本網站與Syncfusion或ZXing.NET沒有關聯、認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供資訊參考,並反映了撰寫時公開可用的資訊。

常見問題

為什麼我應該從Syncfusion Barcode遷移到IronBarcode?

常見的理由包括簡化授權(去除SDK +運行時鑰匙的複雜性)、消除吞吐量限制、獲得原生PDF支持、改善Docker/CI/CD部署,並減少生產程式碼中的API樣板。

如何使用IronBarcode替換Syncfusion的API調用?

用IronBarCode.License.LicenseKey = "key"替換實例建立和授權樣板。用BarcodeReader.Read(path)替換讀取呼叫,用BarcodeWriter.CreateBarcode(data, encoding)替換寫入呼叫。靜態方法不需要實例管理。

從Syncfusion Barcode遷移到IronBarcode時,需要修改多少程式碼?

大多數遷移會導致較少的程式碼行。授權樣板、實例構造函式和顯式格式配置被移除。核心讀/寫操作映射為較短的IronBarcode等價物,且結果物件更清晰。

在遷移期間,我需要同時安裝Syncfusion Barcode和IronBarcode嗎?

不需要。大多數遷移是直接替換而不是並行操作。一次遷移一個服務類,替換NuGet引用,並更新實例化和API呼叫模式後再移動到下一個類。

IronBarcode的NuGet包名稱是什麼?

包名是'IronBarCode'(大寫B和C)。可以用'Install-Package IronBarCode'或'dotnet add package IronBarCode'安裝。程式碼中的using指令是'using IronBarCode;'。

與Syncfusion Barcode相比,IronBarcode如何簡化Docker部署?

IronBarcode是沒有外部SDK文件或掛載許可配置的NuGet封裝。在Docker中,設置IRONBARCODE_LICENSE_KEY環境變數,包在啟動時處理許可驗證。

從Syncfusion遷移後,IronBarcode是否會自動檢測所有條碼格式?

是的。IronBarcode自動檢測所有支持的格式的符號學。不需要顯式的BarcodeTypes枚舉。如果格式已經知道並且性能很重要,BarcodeReaderOptions允許限制搜索空間作為優化。

IronBarcode是否可以不使用單獨的庫讀取PDF中的條碼?

可以。BarcodeReader.Read("document.pdf")原生處理PDF文件。結果包括每個條碼發現的頁碼、格式、值和置信度。不需要外部PDF渲染步驟。

IronBarcode如何處理並行條碼處理?

IronBarcode的靜態方法是無狀態且執行緒安全的。直接使用Parallel.ForEach遍歷文件列表,不需要每個執行緒的實例管理。BarcodeReaderOptions.MaxParallelThreads控制內部執行緒預算。

遷移從Syncfusion Barcode到IronBarcode時,哪些結果屬性會改變?

常見的重命名:BarcodeValue變為Value,BarcodeType變為Format。IronBarcode結果還新增了Confidence和PageNumber。整個解決方案的搜索和替換可處理現有結果處理程式碼中的重新命名。

我如何在CI/CD管道中設置IronBarcode授權?

將IRONBARCODE_LICENSE_KEY作為管道機密儲存,在應用程式啟動程式碼中分配IronBarCode.License.LicenseKey。一個機密涵蓋所有環境,包括開發、測試、分期和生產。

IronBarcode是否支持生成帶有自定義樣式的QR碼?

支持。QRCodeWriter.CreateQrCode()支持通過ChangeBarCodeColor()自定義顏色,通過AddBrandLogo()嵌入logo,可配置錯誤校正級別,以及包括PNG、JPG、PDF和流在內的多種輸出格式。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話