FineUI 官方论坛
标题: Lodop控件打印条形码的源码分享 [打印本页]
作者: 夜冰 时间: 2014-1-10 11:55
标题: Lodop控件打印条形码的源码分享
本帖最后由 夜冰 于 2014-1-10 11:59 编辑
前些日子在固定资产管理软件中用到了打印条形码的功能 ,使用的是Lodop控件,这个控件是免费的, 有人说直接打印会收费,但我没有遇到,今天有空了把打印的那代码分享一下,虽然看上去代码量很大,比较乱,但是只需要画出第一框框后面就简单了,按大小增减就可以了,本例中用的是艾利L7176型纸,在京东上可以买到,只接用A4激光打印机就能打印,图和代码如下:[attach]4140[/attach]
图1:指定的需要打印的内容,查到内容后点击"编码处理",后台就开始画要打印的内容了
[attach]4141[/attach]
图2:这是打印预览的界面,然后点击打印就只接打印出来了
下面是网页的源码
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="F_Txm.aspx.vb" Inherits="ZCLR_F_Txm" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <link type="text/css" href="../CSS/Fmain.css" rel="stylesheet"/>
- <script language="javascript" src="../CSS/LodopFuncs.js"></script>
- <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
- <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 pluginspage="~/CSS/install_lodop.exe"></embed>
- </object>
- <font color="#ff0000"> <script language="javascript" type="text/javascript">
- var LODOP; //声明为全局变量
- function myPreview() {
- CreatePrintPage();
- LODOP.PREVIEW();
- };
- </script> </font>
- </head>
- <body>
- <form id="form1" runat="server">
- <x:PageManager ID="PageManager1" runat="server" AjaxAspnetControls="L_code" />
- <x:Panel ID="Panel1" runat="server" BodyPadding="5px" ShowBorder="false" ShowHeader="false"
- Title="Panel" Layout="Table" TableConfigColumns="6">
- <Items>
- <x:Label Text="输入条码" runat="server" Width="60"></x:Label>
- <x:TextBox ID="txt_bm" runat="server" Label="Label" Text="" Width="300" EmptyText="提示:多个条码之间请用逗号进行分隔"></x:TextBox>
- <x:Button ID="Btn_create" runat="server" Text="编码查询" CssClass="Left20"></x:Button>
- <x:Button ID="Btn_chuli" runat="server" Text="编码处理" CssClass="Left20" <font color="#ff0000">EnableAjax="false"</font>></x:Button>
- <x:ContentPanel ID="ContentPanel1" runat="server" BodyPadding="0px" ShowBorder="false" ShowHeader="False" Title="ContentPanel">
- <asp:Label ID="L_code" runat="server"></asp:Label>
- </x:ContentPanel>
- <x:Button ID="Btn_print" runat="server" Text="打印预览" CssClass="Left20" <font color="#ff0000">OnClientClick="javascript:myPreview()"</font>></x:Button>
- </Items>
- </x:Panel>
- <x:Panel ID="Panel2" runat="server" BodyPadding="0px" ShowBorder="false" ShowHeader="False" Title="Panel" Layout="Fit" Height="585">
- <Items>
- <x:Grid ID="DG_show" runat="server" EnableCheckBoxSelect="false" EnableRowNumber="false" Title="Grid" ShowHeader="false" DataKeyNames="编号,名称,使用部门,使用责任人">
- <Columns>
- <x:BoundField DataField="编号" HeaderText="编号" TextAlign="Center" />
- <x:BoundField DataField="名称" HeaderText="名称" TextAlign="Center" />
- <x:BoundField DataField="使用部门" HeaderText="使用部门" TextAlign="Center" />
- <x:BoundField DataField="使用责任人" HeaderText="使用责任人" TextAlign="Center" />
- </Columns>
- </x:Grid>
- </Items>
- </x:Panel>
- </form>
- </body>
- </html>
复制代码下面是网页的后台代码
- Imports FineUI
- Partial Class ZCLR_F_Txm
- Inherits System.Web.UI.Page
- Dim hr As New OA
- Dim info As String
复制代码好了,其中红色的地方注意一下就可以了.
作者: 夜冰 时间: 2014-1-10 12:17
- Protected Sub Btn_chuli_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_chuli.Click
- '对需要打印的条码进行预先处理
- Dim str As String = ""
- Dim num As Integer = DG_show.Rows.Count
- Dim top As Integer = 11 '每个边各余出4mm间隔
- Dim left As Integer = 3
- Dim jianju As Integer = 2
- Dim W1 As Integer = 63.5
- Dim H1 As Integer = 38.1
- Dim lineH As Integer = 8
- Dim lineW As Integer = 20
- Dim W2 As Integer = 43
- Dim W3 As Integer = 40 '条码的宽度
- Dim H3 As Integer = 14 '条码的高度
- Dim s2 As String = "部门"
- Dim s1 As String = "名称"
- Dim s3 As String = "购买日期"
- Dim bh, mc, sybm, zrr As String
- If num < 1 Or num > 21 Then
- Exit Sub
- End If
- str = "<script language='javascript' type='text/javascript'>"
- str += "function CreatePrintPage() { "
- str += "LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')); "
- str += "LODOP.PRINT_INIT('打印测试用的');"
- str += "LODOP.SET_PRINT_STYLE('FontSize', 10); "
- For i = 0 To num - 1
- bh = DG_show.DataKeys(i)(0)
- mc = DG_show.DataKeys(i)(1)
- sybm = DG_show.DataKeys(i)(2)
- zrr = DG_show.DataKeys(i)(3)
- '第一个框框
- If i = 0 Then
- str += "LODOP.ADD_PRINT_RECT('" & top & "mm', '" & left & "mm', '" & W1 & "mm','" & H1 & "mm', 0, 1); "
- str += "LODOP.ADD_PRINT_LINE('" & top + lineH & "mm','" & left & "mm','" & top + lineH & "mm','" & left + W1 & "mm',0,1);" '第一根直线
- str += "LODOP.ADD_PRINT_LINE('" & top + lineH * 2 & "mm','" & left & "mm','" & top + lineH * 2 & "mm','" & left + W1 & "mm',0,1);" '第二根直线
- str += "LODOP.ADD_PRINT_LINE('" & top + lineH * 3 & "mm','" & left & "mm','" & top + lineH * 3 & "mm','" & left + W1 & "mm',0,1);" '第三根直线
- str += "LODOP.ADD_PRINT_LINE('" & top & "mm','" & left + lineW & "mm','" & top + lineH * 3 & "mm','" & left + lineW & "mm',0,1);" '第一根竖线
- str += "LODOP.ADD_PRINT_TEXT('" & top + 2 & "mm','" & left - 2 & "mm','" & lineW & "mm','" & lineH & "mm','" & s1 & "');" '第一行第一列
- str += "LODOP.SET_PRINT_STYLEA(0,'Alignment',3);"
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH + 2 & "mm','" & left - 2 & "mm','" & lineW & "mm','" & lineH & "mm','" & s2 & "');" '第二行第一列
- str += "LODOP.SET_PRINT_STYLEA(0,'Alignment',3);"
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH * 2 + 2 & "mm','" & left - 2 & "mm','" & lineW & "mm','" & lineH & "mm','" & s3 & "');" '第三列第一称
- str += "LODOP.SET_PRINT_STYLEA(0,'Alignment',3);"
- str += "LODOP.ADD_PRINT_TEXT('" & top + 2 & "mm','" & left + lineW + 2 & "mm','" & W2 & "mm','" & lineH & "mm','" & mc & "');" '第一行第二列
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH + 2 & "mm','" & left + lineW + 2 & "mm','" & W2 & "mm','" & lineH & "mm','" & sybm & "');" '第二行 第二列
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH * 2 + 2 & "mm','" & left + lineW + 2 & "mm','" & W2 & "mm','" & lineH & "mm','" & zrr & "');" '第三行第二列
- str += "LODOP.ADD_PRINT_BARCODE('" & top + lineH * 3 + 2 & "mm','" & left + (W1 - W3) \ 2 & "mm','" & W3 & "mm','" & H3 - 4 & "mm','EAN128A','" & bh & "');" '第四行条形码列
- End If
- '第二个框框
- If i = 1 Then
- str += "LODOP.ADD_PRINT_RECT('" & top & "mm', '" & left + W1 + jianju & "mm', '" & W1 & "mm','" & H1 & "mm', 0, 1); "
- str += "LODOP.ADD_PRINT_LINE('" & top + lineH & "mm','" & left + W1 + jianju & "mm','" & top + lineH & "mm','" & left + W1 * 2 + jianju & "mm',0,1);" '第一根直线
- str += "LODOP.ADD_PRINT_LINE('" & top + lineH * 2 & "mm','" & left + W1 + jianju & "mm','" & top + lineH * 2 & "mm','" & left + W1 * 2 + jianju & "mm',0,1);" '第二根直线
- str += "LODOP.ADD_PRINT_LINE('" & top + lineH * 3 & "mm','" & left + W1 + jianju & "mm','" & top + lineH * 3 & "mm','" & left + W1 * 2 + jianju & "mm',0,1);" '第三根直线
- str += "LODOP.ADD_PRINT_LINE('" & top & "mm','" & left + lineW + W1 + jianju & "mm','" & top + lineH * 3 & "mm','" & left + lineW + W1 + jianju & "mm',0,1);" '第一根竖线
- str += "LODOP.ADD_PRINT_TEXT('" & top + 2 & "mm','" & left + W1 + jianju - 2 & "mm','" & lineW & "mm','" & lineH & "mm','" & s1 & "');" '第一行第一列
- str += "LODOP.SET_PRINT_STYLEA(0,'Alignment',3);"
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH + 2 & "mm','" & left + W1 + jianju - 2 & "mm','" & lineW & "mm','" & lineH & "mm','" & s2 & "');" '第二行第一列
- str += "LODOP.SET_PRINT_STYLEA(0,'Alignment',3);"
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH * 2 + 2 & "mm','" & left + W1 + jianju - 2 & "mm','" & lineW & "mm','" & lineH & "mm','" & s3 & "');" '第三列第一称
- str += "LODOP.SET_PRINT_STYLEA(0,'Alignment',3);"
- str += "LODOP.ADD_PRINT_TEXT('" & top + 2 & "mm','" & left + lineW + W1 + jianju + 2 & "mm','" & W2 & "mm','" & lineH & "mm','" & mc & "');" '第一行第二列
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH + 2 & "mm','" & left + lineW + W1 + jianju + 2 & "mm','" & W2 & "mm','" & lineH & "mm','" & sybm & "');" '第二行 第二列
- str += "LODOP.ADD_PRINT_TEXT('" & top + lineH * 2 + 2 & "mm','" & left + lineW + W1 + jianju + 2 & "mm','" & W2 & "mm','" & lineH & "mm','" & zrr & "');" '第三行第二列
- str += "LODOP.ADD_PRINT_BARCODE('" & top + lineH * 3 + 2 & "mm','" & left + W1 + jianju + (W1 - W3) \ 2 & "mm','" & W3 & "mm','" & H3 - 4 & "mm','EAN128A','" & bh & "');" '第四行条形码列
- End If
- '第三个框框
复制代码
作者: 夜冰 时间: 2014-1-10 12:18
贴不下那么多代码,就贴了画两个框的量
作者: 木土土 时间: 2014-1-10 12:19
源码共享一下呗!
作者: 夜冰 时间: 2014-1-10 12:20
上面发的就是生成打印资产标签的源码.
作者: erp8@live.cn 时间: 2014-1-10 19:58
{:soso_e179:}
作者: 木土土 时间: 2014-1-10 23:03
你这是VB.NET?
作者: 夜冰 时间: 2014-1-12 11:27
嗯,刚开始就学的这,只能一条道走到黑了,还好,很好用
作者: cindy313 时间: 2014-1-23 14:40
本帖最后由 cindy313 于 2014-1-23 14:43 编辑
这全是ean条形码的吗?还只是vb.net,如果是其他的会有何不同
作者: Elwin 时间: 2014-2-6 02:11
哥也出来现一下。。。。{:soso_e113:}见图:
[attach]4259[/attach]
LODOP是好东西啊。。。
作者: highong 时间: 2014-2-6 23:47
学习,贴个比较全的源码吧?
作者: 雏鸟 时间: 2014-2-18 14:32
把这两页截取出来共享出源码来撒,大家一起学习一起用
作者: Nana111 时间: 2014-2-28 14:37
本帖最后由 Nana111 于 2014-2-28 14:38 编辑
我觉得这应该是可以支持ean barcode.但是如果这个能在vb.det 里面支持 scan ean 条形码就好了
作者: cindy313 时间: 2014-3-5 14:39
我觉得这应该是可以支持ean barcode.但是如果这个能在vb.det 里面支持 scan ean 条形码就好了 ...
额,好像绝大部分的scanner都能支持把
作者: lakeman 时间: 2014-3-11 01:52
代码好复杂,我还是用jatoolsPrinter算了,只要写html,不需要拼代码,而且,有免费版本,不需要注册,http://printfree.jatools.com
作者: 狐狸猫 时间: 2016-3-18 16:07
问下你这个是怎么处理的
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/) |
Powered by Discuz! X3.4 |