'dyno printer listen for every row event
Hey guys i have a little issue with my script , im not managing to make the printing script to work for every row.
I know that i need to assign id for every row in the table but
The printing its working only for the first row in table not an expert on java so if someone could help me i will be greatfull.
(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>
<button type="button" class="btn btn-outline-danger" onclick="fail_data('<?=$rs["id"];?>')">Fail</button>
<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>
Solution 1:[1]
The first thing you are going to want to do is make sure you are using the latest version of the dymo connect framework.
Then you need to generate a set of labels using an instance of LabelSetBulder.
Instead of calling the print method on the label object itself, you would then call the printLabel method passing in the generated label set data.
<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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Besworks |
