怎么用C#实现单个打印快递单号
短信预约 -IT技能 免费直播动态提醒
这篇文章主要讲解了“怎么用C#实现单个打印快递单号”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用C#实现单个打印快递单号”吧!
前期准备
安装一个打印插件(K-Print)
http://kdniao.com/documents-instrument
1. 判断你是否安装打印插件和是否升级插件
<asp:HiddenField ID="HiddenField1" runat="server" /> <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" height="0" width="0"> <embed id="LODOP_EM" type="application/x-print-lodop" pluginspage="install_lodop32.exe" height="0" width="0"> </object>
引用打印的js
<script class="lazy" data-src="js/LodopFuncs.js"></script>
js内容:
var CreatedOKLodop7766 = null; function getLodop(oOBJECT, oEMBED) { var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='../yujian110/print/install_lodop32.zip' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>"; var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='../yujian110/print/install_lodop32.zip' target='_self'>执行升级</a>,升级后请重新进入。</font>"; var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='../yujian110/print/install_lodop64.zip' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>"; var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='../yujian110/print/install_lodop64.zip' target='_self'>执行升级</a>,升级后请重新进入。</font>"; var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>"; var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>"; var LODOP; try { //=====判断浏览器类型:=============== var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0); var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0); //=====如果页面有Lodop就直接使用,没有则新建:========== if (oOBJECT != undefined || oEMBED != undefined) { if (isIE) LODOP = oOBJECT; else LODOP = oEMBED; } else { if (CreatedOKLodop7766 == null) { LODOP = document.createElement("object"); LODOP.setAttribute("width", 0); LODOP.setAttribute("height", 0); LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;"); if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA"); else LODOP.setAttribute("type", "application/x-print-lodop"); document.documentElement.appendChild(LODOP); CreatedOKLodop7766 = LODOP; } else LODOP = CreatedOKLodop7766; }; //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:========== if ((LODOP == null) || (typeof (LODOP.VERSION) == "undefined") || (LODOP.VERSION < "6.1.8.0")) { if (is64IE) Version(64); else if (isIE) Version(32); else Version(32); return LODOP; }; //=====如下空白位置适合调用统一功能(如注册码、语言选择等):==== LODOP.SET_LICENSES("", "", "", ""); //============================================================ return LODOP; } catch (err) { if (is64IE) document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML; else document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML; return LODOP; };} //num可选32或64,update有true升级或false不升级 提示升级内容function Version(num, update) { $('#myModal').modal('show');};
写一个打印的方法
<script> var LODOP; //声明为全局变量 function myPrintSetupyunda() {//打印维护 LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')); var s = Array(); s = document.getElementById("<%=HiddenField1.ClientID %>").value.toString().split('~'); LODOP.PRINT_INITA(0, 0, 1500, 1100, "打印"); LODOP.SET_SHOW_MODE("BKIMG_TOP", -25); LODOP.SET_PRINT_PAGESIZE(1, 2300, 1290, "CreateCustomPage"); // LODOP.SET_PRINTER_INDEX(getSelectedPrintIndex()); LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0' class="lazy" data-src='imgs/yunda.jpg'>"); LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW", true); // LODOP.SET_PRINT_STYLE("FontName", "微软雅黑"); LODOP.SET_PRINT_STYLE("FontSize", 11); //LODOP.SET_PRINT_STYLE("Bold", 1); LODOP.ADD_PRINT_TEXT(50, 59, 233, 23, s[0]); LODOP.ADD_PRINT_TEXT(74, 129, 75, 23, s[10]); LODOP.ADD_PRINT_TEXT(123, 114, 263, 70, s[7]); LODOP.ADD_PRINT_TEXT(182, 609, 120, 21, s[4]); LODOP.ADD_PRINT_TEXT(123, 403, 276, 68, s[3]); LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 10); // LODOP.ADD_PRINT_TEXT(377, 462, 195, 50, s[5]); // LODOP.SET_PRINT_STYLEA(0, "FontSize", 9); LODOP.ADD_PRINT_TEXT(206, 154, 113, 23, s[9]); LODOP.ADD_PRINT_TEXT(77, 657, 120, 38, s[2]); LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 1); LODOP.ADD_PRINT_TEXT(77, 461, 110, 35, s[1]); LODOP.ADD_PRINT_TEXT(77, 276, 100, 23, s[8]); var mdate = new Date(); LODOP.ADD_PRINT_TEXT(362, 180, 45, 23, mdate.getFullYear()); LODOP.ADD_PRINT_TEXT(362, 230, 25, 23, mdate.getMonth() + 1); LODOP.ADD_PRINT_TEXT(362, 260, 25, 23, mdate.getDate()); LODOP.ADD_PRINT_TEXT(362, 290, 25, 23, mdate.getHours()); // LODOP.PRINT_SETUP(); //维护模式 // LODOP.PRINT_DESIGN(); //设计模式 LODOP.PREVIEW(); //预览模式 }; </script>
执行这个方法就可以调取快递鸟打印插件进行打印
感谢各位的阅读,以上就是“怎么用C#实现单个打印快递单号”的内容了,经过本文的学习后,相信大家对怎么用C#实现单个打印快递单号这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341