感谢 pmoleri 之前的回答,我成功地使用了 Itext(Itextsharp 版本 5.3.3.0)生成了 B 型条形码 128。这是我写的 c# 代码,希望对您有所帮助:
String stb1 = "123456789";
Barcode128 code128 = new Barcode128();
code128.CodeType = Barcode.CODE128_RAW;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = true;
code128.Code = (StringEncode128(stb1) + "\uffff");
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
bm.Save(Server.MapPath("barcode128.gif"), System.Drawing.Imaging.ImageFormat.Gif);
ImageBarCode128 = Image.GetInstance(Server.MapPath("barcode.gif"));
字符串编码功能:
public String StringEncode128(String text) {
const int Ascii_FNC1 = 102;
const int Ascii_STARTB = 104;
int CharAscii = 0;
for (int CharPos = 0; CharPos < text.Length; ++CharPos)
{
string letter = text.Substring(CharPos, 1);
CharAscii = (int)Convert.ToChar(letter);
if (CharAscii > 127 && CharAscii != Ascii_FNC1) {
throw new Exception(text + "|" + CharAscii);
}
}
StringBuilder outstring = new StringBuilder();
outstring.Append((char)(Ascii_STARTB));
for (int CharPos = 0; CharPos < text.Length; ++CharPos)
{
string letter = text.Substring(CharPos, 1);
CharAscii = (int)Convert.ToChar(letter) - 32;
outstring.Append((char)(CharAscii));
}
return outstring.ToString();
}