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/>