Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fonts code128编码字符串错误_Fonts_Barcode_Code128 - Fatal编程技术网

Fonts code128编码字符串错误

Fonts code128编码字符串错误,fonts,barcode,code128,Fonts,Barcode,Code128,我已从安装了C:/windows/fonts中的code128 font 我使用java方法生成条形码字符串,但当我将结果字符串放入MS word中时 知道我已经安装了字体并使用了来自同一个网站的代码,问题出在哪里呢?我已经将该字体的c#代码转换为java,并且可以正常工作 以下是java代码: public class NewCoder128 { public NewCoder128(){} public String StringToBarcode(Stri

我已从安装了C:/windows/fonts中的code128 font 我使用java方法生成条形码字符串,但当我将结果字符串放入MS word中时

知道我已经安装了字体并使用了来自同一个网站的代码,问题出在哪里呢?我已经将该字体的c#代码转换为java,并且可以正常工作

以下是java代码:

    public class NewCoder128 {


    public NewCoder128(){}


     public String StringToBarcode(String value)
     {
         // Parameters : a string
         // Return     : a string which give the bar code when it is dispayed with CODE128.TTF font
         //              : an empty string if the supplied parameter is no good
         int charPos, minCharPos;
         int currentChar, checksum;
         Boolean isTableB = true, isValid = true;
         String returnValue = "";

         if (value.length() > 0)
         {
             // Check for valid characters
             for (int charCount = 0; charCount < value.length(); charCount++)
             {
                 //currentChar = char.GetNumericValue(value, charPos);
                 //            (int)char.Parse(value.Substring(charCount, 1));
                 System.out.println("count "+charCount);
                 currentChar = value.charAt(charCount);
                 if (!(currentChar >= 32 && currentChar <= 126))
                 {
                     isValid = false;
                     break;
                 }
             }

             // Barcode is full of ascii characters, we can now process it
             if (isValid)
             {
                 charPos = 0;
                 while (charPos < value.length())
                 {
                     if (isTableB)
                     {
                         // See if interesting to switch to table C
                         // yes for 4 digits at start or end, else if 6 digits
                         if (charPos == 0 || charPos + 4 == value.length())
                             minCharPos = 4;
                         else
                             minCharPos = 6;

                         BarcodeConverter128 brc128 = new BarcodeConverter128();

                         minCharPos = brc128.IsNumber(value, charPos, minCharPos);

                         if (minCharPos < 0)
                         {
                             // Choice table C
                             if (charPos == 0)
                             {
                                 // Starting with table C
                                 returnValue =   String.valueOf((char) 205); // char.ConvertFromUtf32(205);
                             }
                             else
                             {
                                 // Switch to table C
                                 returnValue = returnValue + String.valueOf((char) 199);
                             }
                             isTableB = false;
                         }
                         else
                         {
                             if (charPos == 0)
                             {
                                 // Starting with table B
                                 returnValue = String.valueOf((char) 204); // char.ConvertFromUtf32(204);
                             }

                         }
                     }

                     if (!isTableB)
                     {
                         // We are on table C, try to process 2 digits
                         minCharPos = 2;
                         BarcodeConverter128 brcd = new BarcodeConverter128();
                         minCharPos = brcd.IsNumber(value, charPos, minCharPos);
                         if (minCharPos < 0) // OK for 2 digits, process it
                         {

                             currentChar = Integer.parseInt(value.substring(charPos, charPos+2));
                             currentChar = currentChar < 95 ? currentChar + 32 : currentChar + 100;
                             returnValue = returnValue + String.valueOf((char) currentChar);
                             charPos += 2;
                         }
                         else
                         {
                             // We haven't 2 digits, switch to table B
                             returnValue = returnValue + String.valueOf((char) 200);
                             isTableB = true;
                         }
                     }
                     if (isTableB)
                     {
                         // Process 1 digit with table B
                         returnValue = returnValue + value.substring(charPos, charPos+1);
                         charPos++;
                     }
                 }

                 // Calculation of the checksum
                 checksum = 0;
                 for (int loop = 0; loop < returnValue.length(); loop++)
                 {
                     currentChar = returnValue.charAt(loop);
                     currentChar = currentChar < 127 ? currentChar - 32 : currentChar - 100;
                     if (loop == 0)
                         checksum = currentChar;
                     else
                         checksum = (checksum + (loop * currentChar)) % 103;
                 }

                 // Calculation of the checksum ASCII code
                 checksum = checksum < 95 ? checksum + 32 : checksum + 100;
                 // Add the checksum and the STOP
                 returnValue = returnValue +
                         String.valueOf((char) checksum) +
                         String.valueOf((char) 206);
             }
         }

         return returnValue;
     }



}


    class BarcodeConverter128
    {
        /// <summary>
        /// Converts an input string to the equivilant string, that need to be produced using the 'Code 128' font.
        /// </summary>
        /// <param name="value">String to be encoded</param>
        /// <returns>Encoded string start/stop and checksum characters included</returns>
       public BarcodeConverter128(){}

        public int IsNumber(String InputValue, int CharPos, int MinCharPos)
        {
            // if the MinCharPos characters from CharPos are numeric, then MinCharPos = -1
            MinCharPos--;
            if (CharPos + MinCharPos < InputValue.length())
            {
                while (MinCharPos >= 0)
                {
                    if ((int)(InputValue.charAt(CharPos + MinCharPos)) < 48
                        ||(int)(InputValue.charAt(CharPos + MinCharPos)) > 57)
                    {
                        break;
                    }
                    MinCharPos--;
                }
            }
            return MinCharPos;
        }


    }
我已经将其中的c#代码转换为java,它可以正常工作

以下是java代码:

    public class NewCoder128 {


    public NewCoder128(){}


     public String StringToBarcode(String value)
     {
         // Parameters : a string
         // Return     : a string which give the bar code when it is dispayed with CODE128.TTF font
         //              : an empty string if the supplied parameter is no good
         int charPos, minCharPos;
         int currentChar, checksum;
         Boolean isTableB = true, isValid = true;
         String returnValue = "";

         if (value.length() > 0)
         {
             // Check for valid characters
             for (int charCount = 0; charCount < value.length(); charCount++)
             {
                 //currentChar = char.GetNumericValue(value, charPos);
                 //            (int)char.Parse(value.Substring(charCount, 1));
                 System.out.println("count "+charCount);
                 currentChar = value.charAt(charCount);
                 if (!(currentChar >= 32 && currentChar <= 126))
                 {
                     isValid = false;
                     break;
                 }
             }

             // Barcode is full of ascii characters, we can now process it
             if (isValid)
             {
                 charPos = 0;
                 while (charPos < value.length())
                 {
                     if (isTableB)
                     {
                         // See if interesting to switch to table C
                         // yes for 4 digits at start or end, else if 6 digits
                         if (charPos == 0 || charPos + 4 == value.length())
                             minCharPos = 4;
                         else
                             minCharPos = 6;

                         BarcodeConverter128 brc128 = new BarcodeConverter128();

                         minCharPos = brc128.IsNumber(value, charPos, minCharPos);

                         if (minCharPos < 0)
                         {
                             // Choice table C
                             if (charPos == 0)
                             {
                                 // Starting with table C
                                 returnValue =   String.valueOf((char) 205); // char.ConvertFromUtf32(205);
                             }
                             else
                             {
                                 // Switch to table C
                                 returnValue = returnValue + String.valueOf((char) 199);
                             }
                             isTableB = false;
                         }
                         else
                         {
                             if (charPos == 0)
                             {
                                 // Starting with table B
                                 returnValue = String.valueOf((char) 204); // char.ConvertFromUtf32(204);
                             }

                         }
                     }

                     if (!isTableB)
                     {
                         // We are on table C, try to process 2 digits
                         minCharPos = 2;
                         BarcodeConverter128 brcd = new BarcodeConverter128();
                         minCharPos = brcd.IsNumber(value, charPos, minCharPos);
                         if (minCharPos < 0) // OK for 2 digits, process it
                         {

                             currentChar = Integer.parseInt(value.substring(charPos, charPos+2));
                             currentChar = currentChar < 95 ? currentChar + 32 : currentChar + 100;
                             returnValue = returnValue + String.valueOf((char) currentChar);
                             charPos += 2;
                         }
                         else
                         {
                             // We haven't 2 digits, switch to table B
                             returnValue = returnValue + String.valueOf((char) 200);
                             isTableB = true;
                         }
                     }
                     if (isTableB)
                     {
                         // Process 1 digit with table B
                         returnValue = returnValue + value.substring(charPos, charPos+1);
                         charPos++;
                     }
                 }

                 // Calculation of the checksum
                 checksum = 0;
                 for (int loop = 0; loop < returnValue.length(); loop++)
                 {
                     currentChar = returnValue.charAt(loop);
                     currentChar = currentChar < 127 ? currentChar - 32 : currentChar - 100;
                     if (loop == 0)
                         checksum = currentChar;
                     else
                         checksum = (checksum + (loop * currentChar)) % 103;
                 }

                 // Calculation of the checksum ASCII code
                 checksum = checksum < 95 ? checksum + 32 : checksum + 100;
                 // Add the checksum and the STOP
                 returnValue = returnValue +
                         String.valueOf((char) checksum) +
                         String.valueOf((char) 206);
             }
         }

         return returnValue;
     }



}


    class BarcodeConverter128
    {
        /// <summary>
        /// Converts an input string to the equivilant string, that need to be produced using the 'Code 128' font.
        /// </summary>
        /// <param name="value">String to be encoded</param>
        /// <returns>Encoded string start/stop and checksum characters included</returns>
       public BarcodeConverter128(){}

        public int IsNumber(String InputValue, int CharPos, int MinCharPos)
        {
            // if the MinCharPos characters from CharPos are numeric, then MinCharPos = -1
            MinCharPos--;
            if (CharPos + MinCharPos < InputValue.length())
            {
                while (MinCharPos >= 0)
                {
                    if ((int)(InputValue.charAt(CharPos + MinCharPos)) < 48
                        ||(int)(InputValue.charAt(CharPos + MinCharPos)) > 57)
                    {
                        break;
                    }
                    MinCharPos--;
                }
            }
            return MinCharPos;
        }


    }

复制您的输出
Í,BXnߙoÎ
,粘贴到excel中,并将其更改为代码128,然后当我尝试扫描它时,它只是不扫描。它对你有用吗?复制了你的输出
Í,BXnߙoÎ
,粘贴到excel中,并将其更改为代码128,然后当我尝试扫描它时,它就是不扫描。它对你有用吗?