首页 新闻 会员 周边

条形码 打印 asp.net

0
悬赏园豆:20 [已解决问题] 解决于 2012-10-31 16:24
public string bar_code(object str, int ch, int cw, int type_code)
    {
        //str:输入的字符串;ch:要显示条形码的高度;cw:要显示条形码的宽度;type_code:代码类型
        string strTmp = str.ToString();
        string code = strTmp;
        // ToLower()将string转化成小写形式的副本,返回是使用指定区域的性的大小写规则。
        strTmp = strTmp.ToUpper();
        int height = ch;
        int width = cw;
        //将传入的参数进行转化。
        strTmp = strTmp.Replace("0", "_|_|__||_||_|"); ;
        strTmp = strTmp.Replace("1", "_||_|__|_|_||");
        strTmp = strTmp.Replace("2", "_|_||__|_|_||");
        strTmp = strTmp.Replace("3", "_||_||__|_|_|");
        strTmp = strTmp.Replace("4", "_|_|__||_|_||");
        strTmp = strTmp.Replace("5", "_||_|__||_|_|");
        strTmp = strTmp.Replace("7", "_|_|__|_||_||");
        strTmp = strTmp.Replace("6", "_|_||__||_|_|");
        strTmp = strTmp.Replace("8", "_||_|__|_||_|");
        strTmp = strTmp.Replace("9", "_|_||__|_||_|");
        strTmp = strTmp.Replace("A", "_||_|_|__|_||");
        strTmp = strTmp.Replace("B", "_|_||_|__|_||");
        strTmp = strTmp.Replace("C", "_||_||_|__|_|");
        strTmp = strTmp.Replace("D", "_|_|_||__|_||");
        strTmp = strTmp.Replace("E", "_||_|_||__|_|");
        strTmp = strTmp.Replace("F", "_|_||_||__|_|");
        strTmp = strTmp.Replace("G", "_|_|_|__||_||");
        strTmp = strTmp.Replace("H", "_||_|_|__||_|");
        strTmp = strTmp.Replace("I", "_|_||_|__||_|");
        strTmp = strTmp.Replace("J", "_|_|_||__||_|");
        strTmp = strTmp.Replace("K", "_||_|_|_|__||");
        strTmp = strTmp.Replace("L", "_|_||_|_|__||");
        strTmp = strTmp.Replace("M", "_||_||_|_|__|");
        strTmp = strTmp.Replace("N", "_|_|_||_|__||");
        strTmp = strTmp.Replace("O", "_||_|_||_|__|");
        strTmp = strTmp.Replace("P", "_|_||_||_|__|");
        strTmp = strTmp.Replace("R", "_||_|_|_||__|");
        strTmp = strTmp.Replace("Q", "_|_|_|_||__||");
        strTmp = strTmp.Replace("S", "_|_||_|_||__|");
        strTmp = strTmp.Replace("T", "_|_|_||_||__|");
        strTmp = strTmp.Replace("U", "_||__|_|_|_||");
        strTmp = strTmp.Replace("V", "_|__||_|_|_||");
        strTmp = strTmp.Replace("W", "_||__||_|_|_|");
        strTmp = strTmp.Replace("X", "_|__|_||_|_||");
        strTmp = strTmp.Replace("Y", "_||__|_||_|_|");
        strTmp = strTmp.Replace("Z", "_|__||_||_|_|");
        strTmp = strTmp.Replace("-", "_|__|_|_||_||");
        strTmp = strTmp.Replace("*", "_|__|_||_||_|");
        strTmp = strTmp.Replace("/", "_|__|__|_|__|");
        strTmp = strTmp.Replace("%", "_|_|__|__|__|");
        strTmp = strTmp.Replace("+", "_|__|_|__|__|");
        strTmp = strTmp.Replace(".", "_||__|_|_||_|");
        strTmp = strTmp.Replace("_", "<span style='height:" + height + ";width:" + width + ";background:#FFFFFF;'></span>");
        strTmp = strTmp.Replace("|", "<span style='height:" + height + ";width:" + width + ";background:#000000;'></span>");
        if (type_code == 1)
        {

            return strTmp + "<BR>" + code;

        }

        else
        {

            return strTmp;

        }

    }

我用的这个方法,然后在pageload里面用 Response.Write(labTiao.Value = bar_code(en.VlidationCode, 30, 1, 0));来绑定条形码。为什么子在ie上可以显示条形码,打印到A4纸上就没有显示条形码了呢?

青 草 香的主页 青 草 香 | 初学一级 | 园豆:5
提问于:2012-10-26 17:44
< >
分享
最佳答案
1

你好。网上有ASP.Net 方面的BarCode的代码。。http://www.codeproject.com/Articles/30322/Barcodes-in-ASP-NET-applications ,,希望对你有帮助 !

收获园豆:20
在 水 一 方 | 小虾三级 |园豆:1097 | 2012-10-31 16:19

嗯,是的,我也是找到的该网页,参照上面的方法,把条形码,弄出来了,并通过更改里面高度,得到我需要的条形码,以及扫描数据。

谢谢哈!

青 草 香 | 园豆:5 (初学一级) | 2012-10-31 16:24
其他回答(1)
0

可以打印,但是不能识别(我试了),如果非要打印,在打印选项里选择打印背景,就可以了

忘记天涯 | 园豆:154 (初学一级) | 2013-11-25 10:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册