In further testing, I couldn't get it to print multiple labels (if the shipment has more than 1 box). Currently, the base shipping code creates as many labels as specified and appends _1, _2, etc to the png file. I had to move the references to the external js files to within the PHP while loop. I also redid the javascript to be a little simpler, here's the complete code in case anyone has a similar need
PHP Code:
<?php if ($fedex_labels->RecordCount() > 0) {
while(!$fedex_labels->EOF) {
$label = $fedex_labels->fields['labels'];
?>
<script language="javascript" src="includes/javascript/rsvp-3.1.0.min.js"></script>
<script language="javascript" src="includes/javascript/sha-256.min.js"></script>
<script language="javascript" src="includes/javascript/qz-tray.js"></script>
<script language="javascript" src="includes/javascript/trustedCert.js"></script>
<script language="javascript">
qz.websocket.connect().then(function() {
return qz.printers.find("Zebra ZP 500") // Pass the printer name into the next Promise
}).then(function(printer) {
var options = {language: "ZPLII" };
var config = qz.configs.create(printer, options); // Create a default config for the found printer
var data = [{ type: 'image', data: 'images/fedex/<?php echo $label; ?>' }];
return qz.print(config, data);
}).catch(function(e) { console.error(e); });
</script>
<?php $fedex_labels->MoveNext();
}
} ?>
Bookmarks