我有这个程序,我可以在其中打印一些关于托盘(物流)的信息,我需要向其中添加条形码。我环顾四周,发现 http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library看起来确实很有前途。
我添加了 .dll 引用并添加了以下代码:
using BarcodeLib;
// Create barcode size 100, 100 with the ordernumber in type EAN13
Barcode b = new Barcode(order.OrderNr);
b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);
现在我需要知道的是如何将它添加到页面上的特定位置。我目前添加文本的方式看起来像这样:
private void PrintLabel(PrintPageEventArgs e, Graphics g)
{
marginTop = 8;
marginLeft = 5;
int row = marginTop;
g.DrawString("Order nr: ", headerTitleFont, blackText, marginLeft, row);
g.DrawString(order.OrderNr, headerTextFont, blackText, marginLeft + 120, row);
row += 22;
...etc...
Barcode b = new Barcode(order.OrderNr);
b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);
// Print the label b here on position: marginLeft, row
}
最佳答案
根据given documentation , Encode
返回 System.Drawing.Image
。
这非常方便,因为它允许您使用以下方法简单地将其绘制成图形:
Barcode b = new Barcode(order.OrderNr);
Image barcodeImage = b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);
g.DrawImage(barcodeImage, marginLeft, row);
关于c# - 如何将条码图像插入 PrintDialog?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33755727/