我正在使用Barcode 128 C字体并使用IDAutomation库将数字转换为条形码字体。这里是用于将我的号码转换为条形码的cs代码。输入值为009198
public string Code128C(string InputValue)
{
char Code128CStartChar; //start character for Code 128A
char Code128CStopChar; //stop character for Code 128A
char Code128CCheckDigit; //check digit for Code 128A
string EncodedData = ""; //This is the encoded data that we wwill return
int idx = 0; //for loop counter, to loop thru characters passed in
int WeightedTotal = 0; //used to get weighted total of characters for check digit
int LenDataToEncode = 0; //Len of string passed in
char[] InputData; //Character array of input string passed in, so that we can evaluate each charactr
string GoodData = ""; //This is the good data from the InputValue, once we strip out dashes
int iCurrentChars; //The integer value of the 2 characters we are currently working with
string sCurrentChars; //The sting representation of the 2 characters we are working with.
int WeightFactor = 0; //used to calculate the check digit
/* Here we select character set C. We can simply convert the ASCII value to a character
* by casting it as a char type */
Code128CStartChar = (char) ASCII_START128_C;
Code128CStopChar = (char) ASCII_STOP128;
/* <<<< Calculate Modulo 103 Check Digit >>>> */
/* Set WeightedTotal to the value of the start character */
WeightedTotal = ASCII_START128_C - 100;
LenDataToEncode = InputValue.Length;
InputData = InputValue.ToCharArray();
//First check to make sure data is number and remove and dashes
for(idx=0; idx < LenDataToEncode; idx++)
{
if((Char.IsNumber(InputData[idx])) == false)
{
//make sure it is not a dash. If it is a dash, remove it, otherwise get out of the function
if(InputData[idx] != '-')
{
}
}
else
{
GoodData = GoodData + InputData[idx];
}
}
if((GoodData.Length % 2) != 0)
GoodData = "0" + GoodData;
//Calculate Mod 103 Weighted total check digit value, using only the Good Data
LenDataToEncode = GoodData.Length;
WeightFactor = 1;
for(idx=0; idx < LenDataToEncode; idx = idx + 2)
{
/* Get the value of the current character plus the next */
sCurrentChars = GoodData.Substring(idx,2);
iCurrentChars = Convert.ToInt32(sCurrentChars);
//Multiply by the weighting value and add it to the total
WeightedTotal = WeightedTotal + (iCurrentChars * WeightFactor);
WeightFactor = WeightFactor + 1;
//Let's calculate the weighted total.
if(iCurrentChars < 95 && iCurrentChars > 0)
iCurrentChars = iCurrentChars + 32;
else if(iCurrentChars > 94)
iCurrentChars = iCurrentChars + 100;
else if(iCurrentChars == 0)
iCurrentChars = ASCII_SPACE_CHAR;
//Set the return value
EncodedData = EncodedData + (char) iCurrentChars;
}
/* divide the WeightedTotal by 103 and get the remainder, this is the CheckDigitValue*/
iCurrentChars = WeightedTotal % 103;
/* Now that we have the CheckDigitValue, find the corresponding ASCII character
from the table */
if(iCurrentChars < 95 && iCurrentChars > 0)
iCurrentChars = iCurrentChars + 32;
else if(iCurrentChars > 94)
iCurrentChars = iCurrentChars + 100;
else if(iCurrentChars == 0)
iCurrentChars = ASCII_SPACE_CHAR;
//Convert the ASCII value to the character representation.
Code128CCheckDigit = (char) iCurrentChars;
/* Return the EncodedData */
EncodedData = Code128CStartChar + EncodedData + Code128CCheckDigit + Code128CStopChar;
return EncodedData;
} //End Code 128C
上面是我的代码将数字转换为条形码,我安装字体代码128用于在报告中显示但条形码创建问题这里是截图附加。
最后,这个字体由代码“ÍÂ|ÂsΔ输出
返回