Print Zebra zpl labels with serial numbers

The following is a Print Format to print labels use zpl that have individual serial numbers for each label.

I use it from Purchase receipts so that the labels can be printed upon receipt.

It will print directly to the printer (do not put raw printing on) but the output is fussy about which browser you use. SeaMonkey worked the best for me.

In the Print Format choose Custom Format - the following was used in the Purchase receipt doctype:

 <h1>Print Labels</h1>
<p>This works dirrerently on different browsers - SeaMonkey works well.
The Zebra printer driver needs to be set to take text only.</p>
<ul>
<!-- Loop through items received -->
{% for row in doc.items %}

<p> </p>
<!-- The following script is thanks to https://jsfiddle.net/lakerfield/8jtL87n7/4/ -->
<script type="text/javascript">
  function printZpl(zpl) {
    var printWindow = window.open();
    printWindow.document.open('text/plain')
    printWindow.document.write(zpl);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
    
  }
</script>

<!-- Serial numbers are concatenated in the serial_no field and need to be extracted individually  -->

<input type="button" value="Print zpl  "  onclick="printZpl(document.getElementById('zplcode').value)" /><br/>
<textarea id="zplcode" cols="50" rows="12">
{# Loop through each serial number, extract the serial no. and create a label for it  #}
{% for pack in range(row.received_qty) %}
^XA
^FO50,30
^A0N,66,55^FD{{ row.description }}^FS
^FO50,90
^A0N,44,33^FDOrigin:^FS
^FO150,90
^A0N,44,33^FD{{ doc.supplier_name }}^FS
^FO650,100
^A0N,28,22^FD{{ doc.posting_date }}^FS
^FO50,170
^A0B,28,21^FDBatch No^FS  
^FO80,150^BY3
^BCN,80,Y,N,N
^FD{{ row.batch_no }}^FS
^FO50,300
^A0B,28,21^FDSerial No^FS
^FO700,350
^A0N,28,22^FD {{ pack + 1 }} of {{ row.received_qty|string  }}^FS
^FO80,280^BY3
^BCN,80,Y,N,N
^FD{{ row.serial_no[(pack*(row.serial_no|length+1)/row.received_qty)|int:((pack+1)*(row.serial_no|length+1)/row.received_qty-1)|int] }}^FS
^XZ
{% endfor %}
</textarea>

{% endfor %}
</ul>

When you print the next screen will be as follows:

The resultant label will be:
image

12 Likes

@petereb,

Bookmarked… thank you for this.

That some great work.
This leads me to a question on direct output of item cart details from pos screen to serial port connection. That’s vfd screen as the counter till.
Display item names, price from item cart to vfd screen directly from browser to vfd using serial port connection.
Any idea about that?

that is some clever use of the custom print format… :slightly_smiling_face:

Quick question… any reason why you choose not to use the raw printing feature introduced in version 12?

Also, using the raw printing feature will help you to get it working reliable on all browsers… not just on SeaMonkey…

1 Like

The raw printing needs QZ tray to work and the pop up window on the free version can get annoying. But to be honest I am new to ERPNext and I was still at the bottom of the leaning curve when I tried the raw printing.

The zpl solution does (sort of) work in Firefox and Internet Explorer but I found SeaMonkey to be most reliable. Chrome does not work.

The Zebra printer I have is a direct USB model and is used on the shop floor so the choice of browser is not a factor just as long as it works!

1 Like

Hello thank you for the code , How I can add it to item? Like , an item was manufactured, and then it was assigned lets suppose 50 serial numbers , Now I want to print all those? Any thoughts how it can be achieved ? Like the serial number which have been used should not be printed again.

find any solution??
i also want to print all serial number generated?

Has anyone been able to get this working on ERPNext v14?