最近的工程要求條碼打印~~咱用了簡單的方法,直接調用條碼對象生成圖像打印--
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 /// <summary>
5 /// 打印編碼
6 /// </summary>
7 public sealed class PrintBarcode
8 {
9 BarcodeLib.Barcode _Barcode;
10 public PrintBarcode()
11 {
12
13 _Barcode = new BarcodeLib.Barcode();
14 _Barcode.IncludeLabel = true;
15 }
16
17 public System.Drawing.Image Fill(string BarcodeText)
18 {
19 //---12 或者13 長度 的時候用BarcodeLib.TYPE.EAN13這個編碼占小嘿嘿
20 if (BarcodeText.Length >= 12 && BarcodeText.Length <= 13)
21 {
22 return _Barcode.Encode(BarcodeLib.TYPE.EAN13, BarcodeText, 100, 50);
23 }
24
25
26 //-------------------這裡可以適應小於13位置
27 return _Barcode.Encode(BarcodeLib.TYPE.CODE128, BarcodeText, 100,50);
28 }
29
30
31
32 }
再輸出就行了哈,輸出的時候用pb.Fill適配條碼文本~~
BLL.PrintBarcode pb = new PrintBarcode();
/// <summary>
/// 打印事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
//---循環打印消息開始打印
for (int Index = PrintIndex; Index < MessingList.PrintMessing.Count; Index++)
{
IPrintMessing TempMessing = MessingList.PrintMessing[Index];
//---字體大小
int FontSize = MessingList.StyleList.Style[TempMessing.Id].FontSize;
//----特殊碼處理
if (MessingList.StyleList.Style[TempMessing.Id].Type == PrintStyleType.Barcode)
{
e.Graphics.DrawImage(pb.Fill(TempMessing.PrintValue), new System.Drawing.Point(TempMessing.Print_X, TempMessing.Print_Y));
}
else
{
e.Graphics.DrawString(TempMessing.PrintValue, new System.Drawing.Font(new System.Drawing.FontFamily("黑體"), FontSize),
System.Drawing.Brushes.Black, TempMessing.Print_X, TempMessing.Print_Y);
}
////--打印後判斷是否是該頁結束
if (TempMessing.isPageEnd)
{
if (Index >= MessingList.PrintMessing.Count - 1)
{
//---最後一頁從新設置
PrintIndex = 0;
return;
}
else
{
//---重新在執行pd_PrintPage事件
e.HasMorePages = true;
//---負值給打印打印指針,跳過當前索引
PrintIndex = Index + 1;
//---判斷一頁結束
//----跳出循環
return;
}
}
}