在线生成条形码的解决方案(39码、EAN-13)
感谢博主:转自:http://xoyozo.eyuyao.com/blog/barcode.html
public partial class ReceivablesFormView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string code = Get("", , ); this.barcode.InnerHtml = code;
} /// <summary>
/// 获取 EAN-13 条形码(HTML 版)
/// </summary>
/// <param name="s">欲编码的字符串</param>
/// <param name="width">单个条形宽(px)</param>
/// <param name="height">条形高(px)</param>
/// <returns></returns>
public static string Get(string s, int width, int height)
{
int checkcode_input = -;//输入的校验码
if (!Regex.IsMatch(s, @"^\d{12}$"))
{
if (s.Length != )
{
return "字符串长度不正确!";
}
else if (!Regex.IsMatch(s, @"^\d{13}$"))
{
return "存在不允许的字符!";
}
else
{
checkcode_input = int.Parse(s[].ToString());
s = s.Substring(, );
}
} int sum_even = ;//偶数位之和
int sum_odd = ;//奇数位之和 for (int i = ; i < ; i++)
{
if (i % == )
{
sum_odd += int.Parse(s[i].ToString());
}
else
{
sum_even += int.Parse(s[i].ToString());
}
} int checkcode = ( - (sum_even * + sum_odd) % ) % ;//校验码 if (checkcode_input > && checkcode_input != checkcode)
{
return "输入的校验码错误!";
} s += checkcode;//变成13位 // 000000000101左侧42个01010右侧35个校验7个101000000000
// 6 101左侧6位 01010右侧5位 校验1位101000000000 string result_bin = "";//二进制串
result_bin += ""; string type = ean13type(s[]);
for (int i = ; i < ; i++)
{
result_bin += ean13(s[i], type[i - ]);
}
result_bin += "";
for (int i = ; i < ; i++)
{
result_bin += ean13(s[i], 'C');
}
result_bin += ""; string result_html = "";//HTML代码
string color = "";//颜色
int height_bottom = width * ;
foreach (char c in result_bin)
{
color = c == '' ? "#FFFFFF" : "#000000";
result_html += "<div style=\"width:" + width + "px;height:" + height + "px;float:left;background:" + color + ";\"></div>";
}
result_html += "<div style=\"clear:both\"></div>"; result_html += "<div style=\"float:left;color:#000000;width:" + (width * ) + "px;text-align:center;\">" + s[] + "</div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
for (int i = ; i < ; i++)
{
result_html += "<div style=\"float:left;width:" + (width * ) + "px;color:#000000;text-align:center;\">" + s[i] + "</div>";
}
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
for (int i = ; i < ; i++)
{
result_html += "<div style=\"float:left;width:" + (width * ) + "px;color:#000000;text-align:center;\">" + s[i] + "</div>";
}
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;color:#000000;width:" + (width * ) + "px;\"></div>";
result_html += "<div style=\"clear:both\"></div>"; return "<div style=\"background:#FFFFFF;padding:0px;font-size:" + (width * ) + "px;font-family:'楷体';\">" + result_html + "</div>";
}
private static string ean13(char c, char type)
{
switch (type)
{
case 'A':
{
switch (c)
{
case '': return "";
case '': return "";
case '': return "";
case '': return "";//
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
default: return "Error!";
}
}
case 'B':
{
switch (c)
{
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";//
case '': return "";
case '': return "";
case '': return "";
default: return "Error!";
}
}
case 'C':
{
switch (c)
{
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
default: return "Error!";
}
}
default: return "Error!";
}
}
private static string ean13type(char c)
{
switch (c)
{
case '': return "AAAAAA";
case '': return "AABABB";
case '': return "AABBAB";
case '': return "AABBBA";
case '': return "ABAABB";
case '': return "ABBAAB";
case '': return "ABBBAA";//中国
case '': return "ABABAB";
case '': return "ABABBA";
case '': return "ABBABA";
default: return "Error!";
}
}
}
在线生成条形码的解决方案(39码、EAN-13)的更多相关文章
- C# 利用ZXing.Net来生成条形码和二维码
本文是利用ZXing.Net在WinForm中生成条形码,二维码的小例子,仅供学习分享使用,如有不足之处,还请指正. 什么是ZXing.Net? ZXing是一个开放源码的,用Java实现的多种格式的 ...
- 一维码EAN 13简介及其解码实现(zxing-cpp)
一维码EAN 13:属于国际标准条码, 由13个数字组成,为EAN的标准编码型式(EAN标准码). 依结构的不同,EAN条码可区分为: 1. EAN 13码: 由13个数字组成,为EAN的标准编码型 ...
- (zxing.net)一维码EAN 13的简介、实现与解码
一维码EAN 13:属于国际标准条码, 由13个数字组成,为EAN的标准编码型式(EAN标准码). 依结构的不同,EAN条码可区分为: EAN 13码: 由13个数字组成,为EAN的标准编码型式(EA ...
- iOS开发——生成条形码,二维码
- (void)viewDidLoad { [super viewDidLoad]; self.imageView.image = [self generateBarCode:@"15248 ...
- C#利用Zxing.net生成条形码和二维码并实现打印的功能
开篇:zxing.net是.net平台下编解条形码和二维码的工具. 下载地址:http://pan.baidu.com/s/1kTr3Vuf Step1:使用VS2010新建一个窗体程序项目: ...
- 使用js生成条形码以及二维码
一.用js生成条形码这种业务场景不是很常见的,最近刚好又接到这种需求 Google一下,发现github还真有这方面的轮子,感谢github,省去了我们很多造轮子的过程, 好了言归正传,首先引入jsb ...
- 使用谷歌Z生成条形码以及二维码
下载地址:http://zxingnet.codeplex.com/ zxing.net是.net平台下编解条形码和二维码的工具,使用非常方便. 首先下载二进制dll文件,引入工程: using Sy ...
- 第二节 EAN 8 码 / EAN 13 码
EAN码的全名为欧洲商品条码(European Article Number),源於西元1977年,由欧洲十二个工业国家所共同发展出来的一种条码.目前已成为一种国际性的条码系统.EAN条码系统的管理是 ...
- ZXing生成条形码、二维码、带logo二维码
采用的是开源的ZXing,Maven配置如下,jar包下载地址,自己选择版本下载,顺便推荐下Maven Repository <!-- https://mvnrepository.com/art ...
随机推荐
- HTML 超级链接详细讲解
超级链接 超级链接是网站中使用比较频繁的HTML元素,因为网站的各种页面都是由超级链接串接而成,超级链接完成了页面之间的跳转.超级链接是浏览者和服务器的交互的主要手段,在后面的技术中会逐步深化学习. ...
- python __set__ __get__ __delete__
class Attr(object): def __init__(self,attrname,attrtype): self.attrname=attrname self.attrtype=attrt ...
- 11g OCM 考试感悟
11g OCM 考试感悟 PrudentWoo 累,累.真的很累.考前每天全场景的刷两遍.三遍不觉得累.总感觉练习时间不够.考中尽管时间足够.可是压力很大.尤其看到一些和平时训练不一样题目的时候,那种 ...
- draw call 理解和优化
draw call是openGL的描绘次数(directX没怎么研究,但原理应该差不多)一个简单的openGL的绘图次序是:设置颜色→绘图方式→顶点座标→绘制→结束.每帧都会重复以上的步骤.这就是一次 ...
- LoadRunner访问 Mysql数据库
这是很久以前编写的一个测试案例,那时是为了检查大量往Mysql数据库里插入数据,看一下数据库的性能如何?服务器是否会很快就被写满了. 前期的准备工作:Mysql 数据库搭建,LoadRunner,li ...
- ES6 set 应用场景
1.数组去重 let arr = [3, 5, 2, 2, 5, 5]; let unique = [...new Set(arr)]; // [3, 5, 2] 2.并集(Union).交集(Int ...
- 使用xml-rpc调试openerp模块中的函数
运行openerp模块中的函数 有很多方式, 可以在视图中加个按钮然后点击它, 也可以在集成开发环境中强制执行它. 不过, 用python写个小脚本,xml-rpc调用直接执行它, 无疑是最简便的方法 ...
- 关于 yii2 cron运行 console的脚本不运行,可是手动运行成功的原因
在yii2中运行脚本出现了一个问题 手动运行没有问题. 在cron中不运行.最后找出来了原因 打开yii文件(在根文件夹以下) #!/usr/bin/env php <?php /** * Yi ...
- Linux 压缩文件的命令行总结
Linux压缩文件的读取 · *.Z compress 程序压缩的档案: · *.bz2 bzip2 程序压缩的档案: · *.gz gzip 程序压缩 ...
- python selenum ---如何定位一组元素
使用findElements方法定位一组对象 定位一组对象一般用于以下场景: · 批量操作对象,比如将页面上所有的checkbox都勾上 · 先获取一组对象,再在这组对象中过滤出需要具体定位的一些对象 ...