syncfusion-aspnetcore-barcodes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese⚠️ STRICT USAGE RULES — MANDATORY FOR ALL CODE GENERATION
⚠️ 严格使用规则 — 所有代码生成必须遵守
These rules are non-negotiable. They must be followed for every code generation request using this skill.
这些规则不可协商。使用本技能进行每一次代码生成请求时都必须遵守。
Rule A — Use Only Provided Reference Files
规则A — 仅使用提供的参考文件
- You must always read for every request
references/getting-started.md - Read other reference files only if they directly match the user's query:
- → 1D linear barcodes (Code39, Code128, Codabar, etc.)
barcode-types.md - → QR codes with optional logo embedding
qr-code.md - → DataMatrix barcodes
data-matrix.md - → color, size, display text properties
customization.md - → PNG/JPG/Base64 export functionality
export.md
- No external knowledge is allowed:
- ❌ Do NOT use internet documentation
- ❌ Do NOT use training-data assumptions
- ✅ If a feature cannot be confirmed from reference files, apply Rule B
- 每次请求都必须阅读****
references/getting-started.md - 仅当参考文件与用户查询直接匹配时才阅读其他文件:
- → 一维线性条码(Code39、Code128、Codabar等)
barcode-types.md - → 带可选logo嵌入的QR码
qr-code.md - → DataMatrix条码
data-matrix.md - → 颜色、尺寸、显示文本属性
customization.md - → PNG/JPG/Base64导出功能
export.md
- 禁止使用外部知识:
- ❌ 请勿使用互联网文档
- ❌ 请勿使用训练数据中的假设
- ✅ 如果某个功能无法从参考文件中确认,请应用规则B
Rule B — No Guessing, No Inference
规则B — 禁止猜测、禁止推断
If a feature, property, API, or behavior is not explicitly documented in the reference files:
You must NOT:
- Invent properties or methods
- Infer missing APIs or parameters
- Assume deprecated or undocumented features exist
- Generalize from other Syncfusion components
Instead, respond with:
⚠️ NOT DOCUMENTED: [feature name] is not covered in the reference files.
Skipping this feature to avoid generating incorrect code.如果某个功能、属性、API或行为未在参考文件中明确记录:
您不得:
- 虚构属性或方法
- 推断缺失的API或参数
- 假设已弃用或未记录的功能存在
- 从其他Syncfusion组件进行推广
相反,请回复:
⚠️ 未记录:[功能名称]未在参考文件中涵盖。
跳过此功能以避免生成错误代码。Barcode Components Overview
条码组件概述
Syncfusion EJ2 ASP.NET Core provides three barcode components via tag helpers:
| Component | Tag Helper | Best For | Key Properties |
|---|---|---|---|
| BarcodeGenerator | | Linear 1D barcodes (Code39, Code128, Codabar, etc.) | |
| QR Code Generator | | 2D QR codes, URLs, large payloads | |
| DataMatrix Generator | | 2D labels, print media, compact storage | |
All three support:
- ✅ Custom colors ()
foreColor - ✅ Dimension control (,
width)height - ✅ Display text customization
- ✅ Export to PNG/JPG/Base64
Syncfusion EJ2 ASP.NET Core通过标签助手提供三种条码组件:
| 组件 | 标签助手 | 最佳适用场景 | 关键属性 |
|---|---|---|---|
| BarcodeGenerator | | 一维线性条码(Code39、Code128、Codabar等) | |
| QR Code Generator | | 二维QR码、URL、大负载数据 | |
| DataMatrix Generator | | 二维标签、打印介质、紧凑存储 | |
这三个组件均支持:
- ✅ 自定义颜色()
foreColor - ✅ 尺寸控制(,
width)height - ✅ 显示文本定制
- ✅ 导出为PNG/JPG/Base64
Navigation Guide
导航指南
Always read first, then read only files relevant to the request.
references/getting-started.md| Reference File | Read When the Query Involves |
|---|---|
| 📄 getting-started.md | Every request — NuGet setup, tag helper registration, CDN, script manager |
| 📄 barcode-types.md | 1D barcodes, Code39, Code128, Codabar, Code11, Code32, Code93, barcode selection guidance |
| 📄 qr-code.md | QR code rendering, logo embedding, error correction, versioning (v1–v40) |
| 📄 data-matrix.md | DataMatrix overview, rendering, use cases |
| 📄 customization.md | Color ( |
| 📄 export.md | Image export (PNG/JPG), Base64 export, export methods |
请始终先阅读,然后仅阅读与请求相关的文件。
references/getting-started.md| 参考文件 | 当查询涉及以下内容时阅读 |
|---|---|
| 📄 getting-started.md | 所有请求 — NuGet设置、标签助手注册、CDN、脚本管理器 |
| 📄 barcode-types.md | 一维条码、Code39、Code128、Codabar、Code11、Code32、Code93、条码选择指南 |
| 📄 qr-code.md | QR码渲染、logo嵌入、错误纠正、版本控制(v1–v40) |
| 📄 data-matrix.md | DataMatrix概述、渲染、使用场景 |
| 📄 customization.md | 颜色( |
| 📄 export.md | 图片导出(PNG/JPG)、Base64导出、导出方法 |
Quick Start
快速开始
1. Install NuGet Package
1. 安装NuGet包
powershell
Install-Package Syncfusion.EJ2.AspNet.Corepowershell
Install-Package Syncfusion.EJ2.AspNet.Core2. Register Tag Helper (~/Pages/_ViewImports.cshtml
)
~/Pages/_ViewImports.cshtml2. 注册标签助手(~/Pages/_ViewImports.cshtml
)
~/Pages/_ViewImports.cshtmlcshtml
@addTagHelper *, Syncfusion.EJ2cshtml
@addTagHelper *, Syncfusion.EJ23. Add CDN Resources (~/Pages/Shared/_Layout.cshtml
)
~/Pages/Shared/_Layout.cshtml3. 添加CDN资源(~/Pages/Shared/_Layout.cshtml
)
~/Pages/Shared/_Layout.cshtmlcshtml
<head>
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/dist/ej2.min.js"></script>
</head>
<body>
...
<ejs-scripts></ejs-scripts>
</body>cshtml
<head>
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/{{ site.ej2version }}/dist/ej2.min.js"></script>
</head>
<body>
...
<ejs-scripts></ejs-scripts>
</body>4. Basic Examples
4. 基础示例
BarcodeGenerator (Code128)
BarcodeGenerator(Code128)
cshtml
<ejs-barcodegenerator id="barcode"
width="200px"
height="150px"
type="Code128"
value="SYNCFUSION"
mode="SVG">
</ejs-barcodegenerator>cshtml
<ejs-barcodegenerator id="barcode"
width="200px"
height="150px"
type="Code128"
value="SYNCFUSION"
mode="SVG">
</ejs-barcodegenerator>QR Code
QR码
cshtml
<ejs-qrcodegenerator id="qrcode"
width="200px"
height="200px"
value="https://syncfusion.com"
mode="SVG">
</ejs-qrcodegenerator>cshtml
<ejs-qrcodegenerator id="qrcode"
width="200px"
height="200px"
value="https://syncfusion.com"
mode="SVG">
</ejs-qrcodegenerator>DataMatrix
DataMatrix
cshtml
<ejs-datamatrixgenerator id="datamatrix"
width="200px"
height="150px"
value="Syncfusion"
mode="SVG">
</ejs-datamatrixgenerator>cshtml
<ejs-datamatrixgenerator id="datamatrix"
width="200px"
height="150px"
value="Syncfusion"
mode="SVG">
</ejs-datamatrixgenerator>Common Patterns
通用模式
Choose Barcode Type by Content
根据内容选择条码类型
| Use Case | Recommended Type | Reason |
|---|---|---|
| Numeric only, short data | Codabar or Code11 | Compact, simple |
| Alphanumeric, uppercase | Code39 | Industry standard for labels |
| Full ASCII, variable length | Code128 | Most versatile, widely supported |
| Pharmaceutical (Italian) | Code32 | Specialized regulatory requirement |
| Dense alphanumeric data | Code93 | Better compression than Code39 |
| URL or large payload | QR Code | Handles complex data, scannable by phones |
| Label/print media with compact storage | DataMatrix | Industry standard for logistics |
| 使用场景 | 推荐类型 | 原因 |
|---|---|---|
| 仅数字、短数据 | Codabar或Code11 | 紧凑、简单 |
| 字母数字、大写 | Code39 | 标签行业标准 |
| 完整ASCII、可变长度 | Code128 | 最通用、支持广泛 |
| 制药行业(意大利) | Code32 | 专门的法规要求 |
| 高密度字母数字数据 | Code93 | 比Code39压缩率更高 |
| URL或大负载数据 | QR码 | 处理复杂数据,可被手机扫描 |
| 标签/打印介质、紧凑存储 | DataMatrix | 物流行业标准 |
Customize Colors (All Generators)
自定义颜色(所有生成器)
cshtml
<ejs-barcodegenerator id="barcode"
width="200px" height="150px"
type="Code128" value="SYNCFUSION"
foreColor="red" mode="SVG">
</ejs-barcodegenerator>cshtml
<ejs-barcodegenerator id="barcode"
width="200px" height="150px"
type="Code128" value="SYNCFUSION"
foreColor="red" mode="SVG">
</ejs-barcodegenerator>Embed Logo in QR Code
在QR码中嵌入Logo
cshtml
<ejs-qrcodegenerator id="qrcode"
width="200px" height="200px"
value="https://syncfusion.com"
logoUrl="logo.png"
mode="SVG">
</ejs-qrcodegenerator>cshtml
<ejs-qrcodegenerator id="qrcode"
width="200px" height="200px"
value="https://syncfusion.com"
logoUrl="logo.png"
mode="SVG">
</ejs-qrcodegenerator>Export Barcode on Button Click
点击按钮导出条码
cshtml
<button onclick="exportBarcode()">Export as JPG</button>
<script>
function exportBarcode() {
var barcode = document.getElementById("barcode").ej2_instances[0];
barcode.exportImage('MyBarcode', 'JPG');
}
function exportAsBase64() {
var barcode = document.getElementById("barcode").ej2_instances[0];
var base64String = barcode.exportAsBase64Image('PNG');
console.log(base64String);
}
</script>cshtml
<button onclick="exportBarcode()">导出为JPG</button>
<script>
function exportBarcode() {
var barcode = document.getElementById("barcode").ej2_instances[0];
barcode.exportImage('MyBarcode', 'JPG');
}
function exportAsBase64() {
var barcode = document.getElementById("barcode").ej2_instances[0];
var base64String = barcode.exportAsBase64Image('PNG');
console.log(base64String);
}
</script>Hide Display Text
隐藏显示文本
cshtml
<ejs-barcodegenerator id="barcode"
width="200px" height="150px"
type="Code128" value="SYNCFUSION"
displayText.visibility="false"
mode="SVG">
</ejs-barcodegenerator>cshtml
<ejs-barcodegenerator id="barcode"
width="200px" height="150px"
type="Code128" value="SYNCFUSION"
displayText.visibility="false"
mode="SVG">
</ejs-barcodegenerator>When to Use This Skill
何时使用本技能
✅ Rendering any barcode type in ASP.NET Core
✅ Choosing between BarcodeGenerator, QR Code, and DataMatrix
✅ Customizing barcode appearance (color, size, text)
✅ Embedding a logo in a QR code
✅ Exporting barcodes as images or Base64 strings
✅ Selecting appropriate barcode type for use case
✅ Choosing between BarcodeGenerator, QR Code, and DataMatrix
✅ Customizing barcode appearance (color, size, text)
✅ Embedding a logo in a QR code
✅ Exporting barcodes as images or Base64 strings
✅ Selecting appropriate barcode type for use case
✅ 在ASP.NET Core中渲染任何类型的条码
✅ 在BarcodeGenerator、QR码和DataMatrix之间进行选择
✅ 自定义条码外观(颜色、尺寸、文本)
✅ 在QR码中嵌入logo
✅ 将条码导出为图片或Base64字符串
✅ 根据使用场景选择合适的条码类型
✅ 在BarcodeGenerator、QR码和DataMatrix之间进行选择
✅ 自定义条码外观(颜色、尺寸、文本)
✅ 在QR码中嵌入logo
✅ 将条码导出为图片或Base64字符串
✅ 根据使用场景选择合适的条码类型