How to Customize and Add Logos to QR Codes in C# | IronBracode
从Syncfusion Barcode迁移到IronBarcode
本指南提供了从Syncfusion的条码控件迁移到IronBarcode的完整路径—适用于WinForms和WPF的SfBarcodeGenerator。 它涵盖了团队进行这种转变的结构性原因、替换NuGet包和许可证设置的分步快速入门指南、每个常见场景的完整前后代码示例,以及用于审核现有代码库的迁移清单。 如果该项目还使用了其他Syncfusion组件(网格、图表、调度程序),则这些软件包及其注册不会受到影响——只有条形码特定的代码会发生变化。
为什么要从Syncfusion条形码迁移?
读取差距:SfBarcodeGenerator是生成控件,没有读取功能。 这两个类中没有.Scan()方法。 当项目需要从上传的图像、扫描的文档或 PDF 文件中读取条形码时, Syncfusion条形码控件无法提供解决方案。 Syncfusion文档将团队引导至 Barcode Reader OPX 作为解决方案,但这是一个独立的商业产品,必须单独购买、获得许可和维护。
OPX 作为免费软件的付费包装器:条形码阅读器 OPX 内部使用 ZXing .NET一个根据 Apache 2.0 许可证发布的开源条形码读取库。 Apache 2.0 是一种宽松的许可证; 任何.NET开发者都可以通过dotnet add package ZXing.Net直接安装ZXing.Net,并免费将其用于商业应用。一个完整的Syncfusion读取和生成工作流需要两个独立的Syncfusion产品、两个许可证协议和两个API界面—而读取功能本可以直接从OPX封装的免费库中提供。
社区许可概要:Syncfusion的社区许可要求四个条件同时且持续满足:年总收入低于 100 万美元、开发人员不超过 5 人、员工总数不超过 10 人,以及外部融资总额低于 300 万美元。政府机构无论规模大小均不符合资格。违反其中任何一项条件,即立即产生商业许可义务。 A 轮融资通常会使筹集的资金在完成当天超过 300 万美元,从而触发许可费,无论团队规模或收入如何。 商业过渡从$0到每开发者年度Essential Studio订阅——该订阅涵盖整个套件,而不仅仅是条形码组件。 Syncfusion的公布路径是来自销售的定制报价。
版本特定密钥轮换: Syncfusion许可证密钥与特定的 Essential Studio 版本范围绑定。 从 24.x 版本升级到 25.x 版本需要从帐户门户获取新密钥,在每个部署环境的密钥存储中更新该密钥,并重新部署以防止试用水印出现在生产输出中。 对于发布节奏频繁或有多个部署目标的团队来说,这种轮换会变成一种反复出现的运营开销,与生成条形码图像的基本需求不成比例。
基本问题
Syncfusion 的控制架构使得程序化文件生成变得间接。 使用DrawToBitmap,然后保存位图—一个WinForms渲染模式将Windows Forms运行时作为依赖项。
//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
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
IronBarcode与Syncfusion条形码:功能对比
| 特征 | Syncfusion条形码 | IronBarcode |
|---|---|---|
| 条形码生成 | 是的——UI控件(WinForms、WPF、 Blazor、MAUI) | 是的——静态 API,所有环境 |
| 条形码读取 | 不——需要单独的条形码阅读器 OPX。 | 是的——同样的包裹 |
| OPX 读取产品封装了 ZXing .NET (Apache 2.0) | 是 | 不适用 |
| PDF条形码输出 | 不——还需要Syncfusion文件。 | 是—SaveAsPdf()内置 |
| PDF条形码读取 | 否 | 是的——本地人 |
| 服务器端/无头生成 | 需要WinForms运行时(DrawToBitmap) |
原生应用——无需 UI 依赖 |
| Docker/Linux部署 | 有限的 | 全面支持 |
| ASP.NET Core最小 API | 未直接支持 | 全面支持 |
| 带有嵌入式徽标的二维码 | 否 | 是—.AddBrandLogo() |
| 读取时自动进行格式检测 | 不适用 | 是 |
| 社区/免费版 | 社区许可证(四个同时满足的条件) | 30天试用期(仅带水印) |
| 商业许可模式 | 年度订阅(Essential Studio) | 永久(一次性,请参阅ironsoftware.com/csharp/barcode/licensing) |
| 许可证密钥范围 | 版本特定,随NuGet主要更新而轮换 | 主要版本内的版本稳定 |
| 平台注册步骤 | 3-4 个步骤(注册许可证 + 添加 SyncfusionBlazor + 配置 SyncfusionCore + Razor导入) | 一条线路,所有平台 |
| 1D格式范围 | Code 128、Code 39、EAN、UPC、Codabar 等 | 支持所有Syncfusion格式,PlusPDF417、Aztec、MaxiCode、GS1、USPS IMb 等 50 多种格式。 |
| 2D格式范围 | 二维码,DataMatrix | QR码、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
如果在移除条形码包后项目中没有其他Syncfusion包,也请移除许可包:
dotnet remove package Syncfusion.Licensing
dotnet remove package Syncfusion.Licensing
安装IronBarcode一个软件包即可适用于所有平台:
dotnet add package IronBarcode
dotnet add package IronBarcode
步骤 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
步骤 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"
对于 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")
代码迁移示例
WinForms SfBarcode 到 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
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")
BarcodeEncoding.Code128。 DrawToBitmap + .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)
在Razor组件中引用端点:
@page "/fulfillment"
<img src="/barcode/@orderNumber" alt="Order barcode: @orderNumber" />
@code {
private string orderNumber = "ORD-20240315-001";
}
该端点可独立测试,可从任何 HTTP 客户端重用,并且与Blazor Server、带有托管 API 后端的Blazor WebAssembly 以及任何其他 Web 前端兼容。
二维码生成
Syncfusion QR 组件也是浏览器渲染的,没有服务器端输出路径。 IronBarcode在服务器端生成二维码,并直接输出文件。
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")
OPX 阅读器更换
如果项目使用了条形码阅读器 OPX,或者将读取需求推迟到将来购买 OPX 时, IronBarcode会将该依赖项替换为已安装的软件包。 没有衍生产品,也没有第二个许可证。
Syncfusion方案(条形码阅读器 OPX):
// Requires separate Syncfusion条形码 Reader 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 separate Syncfusion条形码 Reader 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
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
条形码读取文档涵盖了从字节数组读取上传处理程序、速度与准确性调整以及多条形码检测。
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
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
条形码 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) |
手动Bitmap → MemoryStream |
.ToPngBinaryData() |
<SfBarcodeGenerator Type="BarcodeType.Code128" Value="..."> |
API端点中的BarcodeWriter.CreateBarcode(value, BarcodeEncoding.Code128) |
<SfQRCodeGenerator Value="..."> |
API端点中的QRCodeWriter.CreateQrCode(value, size) |
BarcodeType.Code128(Blazor枚举) |
BarcodeEncoding.Code128 |
| 条形码阅读器 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"
问题 2:在无头环境下 DrawToBitmap 失败
Syncfusion:SfBarcode.DrawToBitmap依赖于Windows Forms渲染管道。在一个ASP.NET Core进程、Azure Function或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()
问题 3:SfBarcodeGenerator 没有服务器端输出
Syncfusion:SfBarcodeGenerator是一个没有服务器端API界面的Razor组件。 尝试在控制器操作或后台服务中使用它时,会发现没有合适的方法来生成条形码字节。
解决方案:创建一个最小的 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)
问题 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")
问题 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" .
在编写任何迁移代码之前,请先记录以下内容:
- 列出每个调用
SyncfusionLicenseProvider.RegisterLicense的文件 - 列出每个
SfBarcode实例化及其属性分配 - 列出每个
<SfQRCodeGenerator>Razor组件使用 - 列出每个
DrawToBitmap调用和下游保存或显示路径 - 确认条形码阅读器 OPX 是否已安装; 如果是这样,请列出每次读卡通话记录。
代码更新任务
- 从项目中移除每个平台的Syncfusion条形码NuGet包
- 如果没有其他Syncfusion控件剩余,则删除
Syncfusion.LicensingNuGet包 - 安装
IronBarcodeNuGet包 - 在应用程序入口点将
IronBarCode.License.LicenseKey = "KEY" - 如果没有其他Syncfusion控件剩余,删除
builder.Services.AddSyncfusionBlazor() - 如果没有其他Syncfusion控件剩余,删除
builder.ConfigureSyncfusionCore() - 如适用,从
@using Syncfusion.Blazor.BarcodeGenerator - 用
using Syncfusion.Licensing - 用
new SfBarcode()+ 属性分配 +DrawToBitmap块 - 用
BarcodeSymbolType.Code128A(及等效项) - 用
BarcodeType.Code128(Blazor枚举) - 用最小API端点替换每个
<SfBarcodeGenerator>Razor组件,并在组件中加入<img src="...">引用 - 用
<SfQRCodeGenerator>Razor组件 - 将所有条码阅读器OPX阅读调用替换为
BarcodeReader.Read(path) - 在由于未购买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 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 是一个 NuGet 包,不包含任何外部 SDK 文件或已挂载的许可证配置。在 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是否支持生成自定义样式的二维码?
是的。QRCodeWriter.CreateQrCode() 支持通过 ChangeBarCodeColor() 自定义颜色、通过 AddBrandLogo() 嵌入徽标、可配置纠错级别以及多种输出格式,包括 PNG、JPG、PDF 和流媒体。

