admin管理员组文章数量:1621899
2024年6月7日发(作者:)
C# 在PDF中创建条码、二维码
条形码技术是一种广泛应用于商业、邮政、图书管理、仓储、工业生产过程控制、交通运输、
包装、配送等领域的自动识别技术。它是由一组规则排列的条、空及其对应字符组成,用以
表示一定信息的标识。同时,技术的创新也使二维码技术得以发展应用。因此,本篇文章将
对如何在PDF文档中创建条码和二维码进行讲述。
注:本身支持创建以下几种类型的条码,包括Codabar、Code 11、Code 32、Code
39、Code128、Code 93等,而创建其他类型的条码或者二维码时,需要使用e。
下面在PDF中创建二维码的示例中,就需要同时使用到和
。
PS:
这里可以使用Free for .NET,下载安装后,dll文件可在安装路径下的Bin文
件夹下获取。也可以通过Nuget网站下载安装。
1. 生成条码
Dll
引用:
C#
using g;
using ;
using cs;
using e;
namespace DrawPdfBarcode
{
class Program
{
static void Main(string[] args)
{
//实例化一个PdfDocument类
PdfDocument doc = new PdfDocument();
//设置PDF Margin,并添加section
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
= tUnits(2.54f, eter,
);
= ;
= tUnits(3.17f, eter,
);
= ;
PdfSection section = ();
s = margin;
= PdfPageSize.A4;
// 添加一页,设置文字字体及格式
PdfPageBase page = ();
float y = 10;
PdfBrush brush1 = ;
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12f,
), true);
RectangleF rctg = new RectangleF(new PointF(0, 0), Size);
PdfLinearGradientBrush brush2
= new PdfLinearGradientBrush(rctg, , Red,
al);
//绘入条码
PdfTextWidget text = new PdfTextWidget();
= font1;
= "Codabar:";
PdfLayoutResult result = (page, 0, y);
page = ;
y = + 2;
PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
eToTextGapHeight = 1f;
CheckDigit = true;
eckDigit = true;
splayLocation = ;
lor = ;
(page, new PointF(0, y));
y = + 5;
//绘入条码 Code11
= "Code11:";
result = (page, 0, y);
page = ;
y = + 2;
PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");
eToTextGapHeight = 1f;
splayLocation = ;
lor = ;
(page, new PointF(0, y));
y = + 5;
//绘入条码 Code128-A
版权声明:本文标题:C# 在PDF中创建条码、二维码 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1717748863a605624.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论