none
在asp.net(C#)中如何用TSCActiveX.dll打印条形码?? RRS feed

答案

  • ASP.Net是在服务器上运行的,你想在服务器上打印?

    没有DLL的文档的话,联系TSCActiveX.dll的作者以获得这个DLL的使用方法,这个DLL不是ASP.Net的一部分。



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2010年9月20日 15:39
    版主
  • 你好:

    你可以将条件码输出到页面上。直接打印。这有段相当的JS代码,请参照:

     <script type='text/javascript'>
        //将卡号写入门禁卡中
        function writCardNo() {
          var cardNo = writCardNo.arguments[0];
          return WriteCardInfo(cardNo);
        }
        //打印标签姓名、有效期strName, strDate
        function printBarCode() {
          LoadPrinter();
          //创建条码打印机ActiveX对象
          var TSCObj;
          try {
            TSCObj = new ActiveXObject('TSCActiveX.TSCLIB');
          }
          catch (err) {
            alert("请确认\n\t1、是否已经注册TSCActiveX.dll;\n\t2、启用ActiveX控件和插件");
            return false;
          }
          var Printerobj = document.getElementById("printers"); //读取打印机
          //检测打印机
          if (Printerobj == null || Printerobj.value == "") {
            alert("请选择打印机");
            return false;
          }
          //开始打印询问
          if (!confirm("现在开始打印!")) {
            return false;
          }
          //连接打印机
          TSCObj.ActiveXopenport(Printerobj.value);
          TSCObj.ActiveXsetup("80", "20", "10", "8", "0", "2", "0");
          TSCObj.ActiveXsendcommand("SET TEAR ON");
          //清空打印机缓存
          TSCObj.ActiveXclearbuffer();
          //打印标签
          var vdeptName=printBarCode.arguments[0];
          var vName=printBarCode.arguments[1];
          var vtel=printBarCode.arguments[2];
          var vcompany=printBarCode.arguments[3];
          var vtime=printBarCode.arguments[4];
    
          TSCObj.ActiveXwindowsfont(10, 25, 24, 0, 2, 0, "arial",vcompany);
          TSCObj.ActiveXwindowsfont(10, 55, 24, 0, 2, 0, "arial",vName);
          TSCObj.ActiveXwindowsfont(10, 85, 24, 0, 2, 0, "arial",vtel);
          TSCObj.ActiveXwindowsfont(10, 115, 24, 0, 2, 0, "arial", "有效期至:" + vtime);
          TSCObj.ActiveXprintlabel("1", "1");
          //关闭打印机
          TSCObj.ActiveXcloseport();
          return true;
        }
        //获取打印机
        function LoadPrinter() {
          var locator;
          try {
            locator = new ActiveXObject('WbemScripting.SWbemLocator');
          }
          catch (err) {
            alert("请确认\n\t1、是否已经注册WbemScripting.dll;\n\t2、启用ActiveX控件和插件");
            return false;
          }
          var service = locator.ConnectServer(".");
          var properties = service.ExecQuery("SELECT * FROM Win32_Printer");
          var e = new Enumerator(properties);
          var defaultPrinter; //默认打印机
          var obj = document.getElementById("printers"); //读取打印机列表
          //清除列表
          for (i = obj.options.length - 1; i >= 0; i--)
            obj.options[i] = null;
          //循环获取打印机 
          for (; !e.atEnd(); e.moveNext()) {
            var p = e.item();
            opt = new Option();
            opt.text = p.Name;
            opt.value = p.Name;
            obj.options.add(opt);
            if (p.Default == true) {
              defaultPrinter = p.Name;
            }
          }
    
          for (var i = 0; i < obj.options.length; i++)//设置默认打印机
          {
            if (obj.options[i].value == defaultPrinter)
              obj.options[i].selected = true;
          }
        }
        //添加打印机向导
        function addprinter() {
          try {
            var objShell = new ActiveXObject("wscript.shell");
            objShell.Run("rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter");
            objShell = null;
          }
          catch (e) {
            alert("请确认\n\t1、是否已经注册wscript.dll;\n\t2、启用ActiveX控件和插件");
          }
        }
      </script>
    
    

    http://zhidao.123doing.com/35095.html

    希望对你有所帮助。

    2010年9月23日 6:40
    版主

全部回复

  • ASP.Net是在服务器上运行的,你想在服务器上打印?

    没有DLL的文档的话,联系TSCActiveX.dll的作者以获得这个DLL的使用方法,这个DLL不是ASP.Net的一部分。



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2010年9月20日 15:39
    版主
  • 可以在服务器打印到xps文件,然后用sl4下载后打印
    入了ipad,最近用ipad上论坛
    2010年9月21日 0:43
  • 你好:

    你可以将条件码输出到页面上。直接打印。这有段相当的JS代码,请参照:

     <script type='text/javascript'>
        //将卡号写入门禁卡中
        function writCardNo() {
          var cardNo = writCardNo.arguments[0];
          return WriteCardInfo(cardNo);
        }
        //打印标签姓名、有效期strName, strDate
        function printBarCode() {
          LoadPrinter();
          //创建条码打印机ActiveX对象
          var TSCObj;
          try {
            TSCObj = new ActiveXObject('TSCActiveX.TSCLIB');
          }
          catch (err) {
            alert("请确认\n\t1、是否已经注册TSCActiveX.dll;\n\t2、启用ActiveX控件和插件");
            return false;
          }
          var Printerobj = document.getElementById("printers"); //读取打印机
          //检测打印机
          if (Printerobj == null || Printerobj.value == "") {
            alert("请选择打印机");
            return false;
          }
          //开始打印询问
          if (!confirm("现在开始打印!")) {
            return false;
          }
          //连接打印机
          TSCObj.ActiveXopenport(Printerobj.value);
          TSCObj.ActiveXsetup("80", "20", "10", "8", "0", "2", "0");
          TSCObj.ActiveXsendcommand("SET TEAR ON");
          //清空打印机缓存
          TSCObj.ActiveXclearbuffer();
          //打印标签
          var vdeptName=printBarCode.arguments[0];
          var vName=printBarCode.arguments[1];
          var vtel=printBarCode.arguments[2];
          var vcompany=printBarCode.arguments[3];
          var vtime=printBarCode.arguments[4];
    
          TSCObj.ActiveXwindowsfont(10, 25, 24, 0, 2, 0, "arial",vcompany);
          TSCObj.ActiveXwindowsfont(10, 55, 24, 0, 2, 0, "arial",vName);
          TSCObj.ActiveXwindowsfont(10, 85, 24, 0, 2, 0, "arial",vtel);
          TSCObj.ActiveXwindowsfont(10, 115, 24, 0, 2, 0, "arial", "有效期至:" + vtime);
          TSCObj.ActiveXprintlabel("1", "1");
          //关闭打印机
          TSCObj.ActiveXcloseport();
          return true;
        }
        //获取打印机
        function LoadPrinter() {
          var locator;
          try {
            locator = new ActiveXObject('WbemScripting.SWbemLocator');
          }
          catch (err) {
            alert("请确认\n\t1、是否已经注册WbemScripting.dll;\n\t2、启用ActiveX控件和插件");
            return false;
          }
          var service = locator.ConnectServer(".");
          var properties = service.ExecQuery("SELECT * FROM Win32_Printer");
          var e = new Enumerator(properties);
          var defaultPrinter; //默认打印机
          var obj = document.getElementById("printers"); //读取打印机列表
          //清除列表
          for (i = obj.options.length - 1; i >= 0; i--)
            obj.options[i] = null;
          //循环获取打印机 
          for (; !e.atEnd(); e.moveNext()) {
            var p = e.item();
            opt = new Option();
            opt.text = p.Name;
            opt.value = p.Name;
            obj.options.add(opt);
            if (p.Default == true) {
              defaultPrinter = p.Name;
            }
          }
    
          for (var i = 0; i < obj.options.length; i++)//设置默认打印机
          {
            if (obj.options[i].value == defaultPrinter)
              obj.options[i].selected = true;
          }
        }
        //添加打印机向导
        function addprinter() {
          try {
            var objShell = new ActiveXObject("wscript.shell");
            objShell.Run("rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter");
            objShell = null;
          }
          catch (e) {
            alert("请确认\n\t1、是否已经注册wscript.dll;\n\t2、启用ActiveX控件和插件");
          }
        }
      </script>
    
    

    http://zhidao.123doing.com/35095.html

    希望对你有所帮助。

    2010年9月23日 6:40
    版主