weixin_47313565 2023-01-16 16:19 采纳率: 50%
浏览 90
已结题

zerba打印机js调用,打印出来的文件向左偏移,怎么将文件正常打印出来

zerba打印机js调用,打印出来的文件向左偏移
 <script type="text/javascript">
    var selected_device;
    var devices = [];
    function setup()
    {
      //Get the default device from the application as a first step. Discovery takes longer to complete.
      BrowserPrint.getDefaultDevice("printer", function(device)
      {

        //Add device to list of devices and to html select element
        selected_device = device;
        devices.push(device);
        var html_select = document.getElementById("selected_device");
        var option = document.createElement("option");
        option.text = device.name;
        html_select.add(option);

        //Discover any other devices available to the application
        BrowserPrint.getLocalDevices(function(device_list){
          for(var i = 0; i < device_list.length; i++)
          {
            //Add device to list of devices and to html select element
            var device = device_list[i];
            if(!selected_device || device.uid != selected_device.uid)
            {
              devices.push(device);
              var option = document.createElement("option");
              option.text = device.name;
              option.value = device.uid;
              html_select.add(option);
            }
          }
        }, function(){alert("Error getting local devices")},"printer");

      }, function(error){
        alert(error);
      })
    }
    var readCallback = function(readData) {
      if(readData === undefined || readData === null || readData === "")
      {
        alert("No Response from Device");
      }
      else
      {
        alert(readData);
      }

    }
    var errorCallback = function(errorMessage){
      alert("Error: " + errorMessage);
    }
    function getDeviceCallback(deviceList)
    {
      alert("Devices: \n" + JSON.stringify(deviceList, null, 4))
    }

    function sendImage(imageUrl)
    {
      //window.location.href获取当前域名
      // url = window.location.href.substring(0, window.location.href.lastIndexOf("/"));
      // url = url + "/" + imageUrl+"/"+{$tpid};
      url = imageUrl;

      //selected_device用来接收要控制的设备
      selected_device.convertAndSendFile(url, undefined, errorCallback)
    }
    function onDeviceSelected(selected)
    {
      for(var i = 0; i < devices.length; ++i){
        if(selected.value == devices[i].uid)
        {
          selected_device = devices[i];
          return;
        }
      }
    }
    //window.onload加载事件在页面内容加载完成之后立即执行相应的函数
    window.onload = setup;
  </script>
</head>
<body>
<span style="padding-right:50px; font-size:200%">Zebra Browser Print Test Page</span><br/>
<span style="font-size:75%">This page must be loaded from a web server to function properly.</span><br><br>
打印机: <select id="selected_device" onchange=onDeviceSelected(this);></select> <!--  <input type="button" value="Change" onclick="changeDevice();">--> <br/><br/>
<!--<input type="button" value="发送配置标签" onclick="writeToSelectedPrinter('~wc')"><br/><br/>-->
<!--<input type="button" value="发送ZPL标签" onclick="writeToSelectedPrinter('^XA^FO200,200^A0N36,36^FDTest Label^FS^XZ')"><br/><br/>-->
<!--<input type="button" value="Get Status" onclick="writeToSelectedPrinter('~hs'); readFromSelectedPrinter()"><br/><br/>-->
<input type="button" value="打印 JPG 图片" onclick="sendImage('{$tpl}' );"><br/><br/>

遇到的现象和发生背景,请写出第一个错误信息

img

  • 写回答

5条回答 默认 最新

  • heart_6662 2023-01-16 16:34
    关注

    望采纳!!!点击回答右侧采纳即可!!
    首先,建议你可以检查是否有任何配置设置导致图像向左偏移,例如打印机设置或打印驱动程序设置。

    如果配置设置没有问题,则可能是代码中的问题。在这种情况下,你可以尝试以下解决方案:

    1.检查selected_device.ActiveXsetup=("100", "40", "4", "15", "1", "2.5", "0") 这行代码是否正确。这可能导致图像向左偏移。
    
    2.在调用selected_device.convertAndSendFile(url, undefined, errorCallback) 之前,请检查图像URL是否正确。
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 1月27日
  • 已采纳回答 1月19日
  • 修改了问题 1月16日
  • 创建了问题 1月16日