dyno打印机监听每一行事件



嘿,伙计们,我的脚本有点问题,我无法使打印脚本适用于每一行。

我知道我需要为表中的每一行分配id,但除外

打印仅适用于表中的第一行不是java方面的专家,所以如果有人能帮助我,我会非常高兴的。

(function()
{

// called when the document completly loaded
function onload()
{
var model_text    = document.getElementById('model_text');
var defect_text = document.getElementById('defect_text');
var imei_text = document.getElementById('imei_text');
var batch_text = document.getElementById('batch_text'); 
var printButton = document.getElementById('printButton');
// prints the label
printButton.onclick = function()
{
try
{
// open label
';
var label = dymo.label.framework.openLabelXml(labelXml);



// set label text
label.setObjectText("model_text", model_text.value);
label.setObjectText("defect_text", defect_text.value);
label.setObjectText('imei_text', imei_text.value);        
label.setObjectText('batch_text', batch_text.value); 

// select printer to print on
// for simplicity sake just use the first LabelWriter printer
var printers = dymo.label.framework.getPrinters();
if (printers.length == 0)
throw "No DYMO printers are installed. Install DYMO printers.";
var printerName = "";
for (var i = 0; i < printers.length; ++i)
{
var printer = printers[i];
if (printer.printerType == "LabelWriterPrinter")
{
printerName = printer.name;
break;
}
}
if (printerName == "")
throw "No LabelWriter printers found. Install LabelWriter printer";
// finally print the label
label.print(printerName);
}
catch(e)
{
alert(e.message || e);
}
}
};
// register onload event
if (window.addEventListener)
window.addEventListener("load", onload, false);
else if (window.attachEvent)
window.attachEvent("onload", onload);
else
window.onload = onload;
} ());
<script src = "dymo.connect.framework.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintLabels.js" type="text/javascript" charset="UTF-8"> </script>

<title>Phone list</title>
</head>

<body>


<div class="container">
<span id="success_message"></span>
<div class="card">

<div class="card-header">


<div class="row">
<div class="col col-md-6"> list</div>
</div>
</div>
<div class="card-body">
<div class="table-responsive">

<table id="empTable" class="table table-striped" style="width:100%">
<thead>
<tr>
<th>Imei</th>
<th>Date</th>
<th>Engineer</th>
<th>Model</th>
<th>Labour</th>
<th>Price</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>

<?php  foreach ($results as $rs)   { ;?>  
<tr>
<td><input type="" id="id" name="id" value="<?= $rs['id'] ?>"></td>
<td><input type="hidden" id="imei_text" name="imei_text" value="<?= $rs['imei'] ?>"><?= $rs['imei'] ?></td>
<td><?= $rs['date'] ?></td>
<td ><input type="hidden" id="defect_text" name="defect_text" value="<?= $rs['engineer'] ?>"><?= $rs['engineer'] ?></td>
<td><input type="hidden" id="model_text" name="model_text" value="<?= $rs['model'] ?>"><?= $rs['model'] ?></td>
<td><?= $rs['job1_n'] ?></td>
<td><?= $rs['total'] ?></td>
<td><input type="hidden" id="batch_text" name="batch_text" value="<?= $rs['status'] ?>"><?= $rs['status'] ?></td>
<td>
<button type="button" class="btn btn-outline-success" onclick="pass_data('<?=$rs["id"];?>')" >Pass</button>&nbsp;
<button type="button" class="btn btn-outline-danger" onclick="fail_data('<?=$rs["id"];?>')">Fail</button>&nbsp;
<input type="submit" id="printButton" name="printButton" value="Print" />
</td>
</tr>
<?php $result++;
} 

echo "Count = $result";
?>
</tbody>
<tfoot>
<tr>
<th>Imei</th>
<th>Date</th>
<th>Engineer</th>
<th>Model</th>
<th>Labour</th>
<th>Price</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
</table>

</div>
</div>
</div>
</div>
</body>
</html>

您要做的第一件事是确保您使用的是最新版本的dymo连接框架。

然后,您需要使用LabelSetBulder的实例生成一组标签。

您不需要对标签对象本身调用print方法,而是调用传递生成的标签集数据的printLabel方法。

<script src="http://labelwriter.com/software/dls/sdk/js/dymo.connect.framework.js"></script>
<button id="print"> Print </button>
<script>
let data = [
{ text : 'TEST1' },
{ text : 'TEST2' }
];
function init() {
// Fetch your xml format label template
let labelXml = `
<?xml version="1.0" encoding="utf-8"?>
...
<BarcodeObject>
<Name>Barcode</Name>
<Text></Text>
</BarcodeObject>
`;
// Build a label object from xml data
let barcodeLabel = dymo.label.framework.openLabelXml(labelXml);

// Verify label validity
if (!barcodeLabel.isValidLabel()) {
throw new Error('invalid label xml');
}
// Initialze a label set builder
let labelSetBuilder = new dymo.label.framework.LabelSetBuilder();
// Loop over data and add each record to the label set
data.forEach(row = > {
let r = labelSetBuilder.addRecord();
r.setText('Barcode', row.text);)
});
// Get label set data as an xml string
let labelSetXml = labelSetBuilder.toString();
// Get printer name
let printers = dymo.label.framework.getLabelWriterPrinters();
let printerName = printers[0].name;
// Set print parameters such as print quality, tape cut mode, etc 
// See http://labelwriter.com/software/dls/sdk/PrintParams.xsd
let parametersXml = '';
// Attach dymo print action to button
let printButton = document.querySelector('button#print');
printButton.addEventListener('click', event => {
dymo.label.framework.printLabel(printerName, parametersXml, labelXml, labelSetXml);
});
});
dymo.label.framework.init(init);
</script>

相关内容

  • 没有找到相关文章

最新更新