def generateLabel(self, dcNo='0', upc='0', title='', price='$0', ip_add='10.1.10.155', width=2.25, height=1.25): zpl = ZPLDocument() zpl.add_comment('DC No') zpl.add_field_origin(320, 25) zpl.add_font('A', zpl._ORIENTATION_NORMAL, 10) zpl.add_field_data(str(dcNo)) zpl.add_comment('UPC') upcPos = self.__getUPCPosition(upc) zpl.add_field_origin(int(upcPos), 50) code128_data = str(upc) bc = Code128_Barcode(code128_data, 'N', 50, 'Y') zpl.add_barcode(bc) zpl.add_comment('Date') zpl.add_field_origin(30, 180) zpl.add_font('S', zpl._ORIENTATION_NORMAL, 16) zpl.add_field_data(datetime.datetime.now().strftime('%d/%m/%Y')) zpl.add_comment('Price') zpl.add_field_origin(290, 180) zpl.add_font('G', zpl._ORIENTATION_NORMAL, 18) zpl.add_field_data(str('$' + price)) self.printZPL(zpl)
def test_field_data(): zdoc = ZPLDocument() zdoc.add_field_data('data') assert (zdoc.zpl_bytes == b'^XA\n^FDdata^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_field_data(['data', 'data2', 'data3']) assert (zdoc.zpl_bytes == b'^XA\n^FDdata^FSdata2^FSdata3^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_field_data('data\ndata2') assert (zdoc.zpl_bytes == b'^XA\n^FDdata\ndata2^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_field_data('data\ndata2', True) assert (zdoc.zpl_bytes == b'^XA\n^FDdata\\&data2^FS\n^XZ')
from simple_zpl2 import ZPLDocument, QR_Barcode zpl = ZPLDocument() zpl.add_comment('Create a QR Code') zpl.add_field_origin(20, 20) qr_data = 'This is data inside a QR code. This is a barcode often read by cell phones.' qr = QR_Barcode(qr_data, 2, 2, zpl._QR_ERROR_CORRECTION_STANDARD) zpl.add_barcode(qr) zpl.add_comment('Now some text') zpl.add_field_origin(200, 20) zpl.add_font('C', zpl._ORIENTATION_NORMAL, 15) zpl.add_field_data('Text on Label') # Print generated text print(zpl.zpl_text)
from PIL import Image import io from simple_zpl2 import ZPLDocument, Code128_Barcode # Build up ZPL label zpl = ZPLDocument() zpl.add_comment("Barcode and text") zpl.add_field_origin(20, 20) code128_data = 'TEST BARCODE' bc = Code128_Barcode(code128_data, 'N', 30, 'Y') zpl.add_barcode(bc) zpl.add_comment('Just Text') zpl.add_field_origin(20, 100) zpl.add_font('A', zpl._ORIENTATION_NORMAL, 15) zpl.add_field_data('Just Text Here') # Get PNG byte array png = zpl.render_png(label_width=2, label_height=1) # render fake file from bytes fake_file = io.BytesIO(png) img = Image.open(fake_file) # Open image with the default image viewer on your system img.show()