def _generate_zpl2_data(self, record, page_count=1, **extra):
        self.ensure_one()
        label_data = zpl2.Zpl2()

        labelary_emul = extra.get('labelary_emul', False)
        for page_number in range(page_count):
            # Initialize printer's configuration
            label_data.label_start()
            if not labelary_emul:
                label_data.print_width(self.width)
            label_data.label_encoding()

            label_data.label_home(self.origin_x, self.origin_y)

            self._generate_zpl2_components_data(label_data,
                                                record,
                                                page_number=page_number,
                                                page_count=page_count,
                                                **extra)

            # Restore printer's configuration and end the label
            if self.restore_saved_config:
                label_data.configuration_update(zpl2.CONF_RECALL_LAST_SAVED)
            label_data.label_end()

        return label_data.output()
예제 #2
0
    def run(self):
        try:
            self.parseArguments()

            self.zpl = zpl2.Zpl2(firmware='V45.11.7ZA')

            # label data
            self.args.labelWidth = int(self.parseUnit(self.args.labelWidth))
            self.args.labelHeight = int(self.parseUnit(self.args.labelHeight))

            self.zpl.StartFormat()
            self.zpl.SetDarkness(self.args.darkness)
            self.zpl.PrintWidth(self.args.labelWidth)
            self.zpl.LabelLength(self.args.labelHeight)
            self.zpl.LabelTop(self.args.labelTop)
            self.zpl.ChangeInternationalFontEncoding('cp850')

            if (self.args.type == 'text'):
                self.labelTypeText()
            elif (self.args.type == 'dhl'):
                self.labelTypeDHL()
            elif (self.args.type == 'image'):
                self.labelTypeImage()
            else:
                return

            # Grid
            if (self.args.gridSpacing):
                self.addGrid(spacing=int(self.args.gridSpacing))

            self.zpl.EndFormat()

            if (self.args.dryRun):
                print(self.zpl.getAllBytes())
            else:
                singleData = self.zpl.getAllBytes()
                allData = b"".join([singleData * self.args.quantity])
                self.cupsPrint(allData)

        except Exception as e:
            if (self.args.debug):
                traceback.print_exc()
            if (len(e.args) > 0):
                sys.exit(e.args[0])
            else:
                sys.exit("Unknown error: %s" % sys.exc_info()[0])
예제 #3
0
 def testFieldOriginNewFirmware(self):
     self.zpl = zpl2.Zpl2(firmware="V60.14.7ZA")
     self.zpl.FieldOrigin(1, 2, 1)
     self.assertEqual(self.zpl, [b'^FO1,2,1'])
예제 #4
0
 def setUp(self):
     self.zpl = zpl2.Zpl2(firmware="V45.11.7ZA")
     pass
예제 #5
0
    def createLabelFromData(self, data):
        self.zpl = zpl2.Zpl2(firmware='V45.11.7ZA')

        # label data
        labelWidth = 900
        labelHeight = 300

        # barcode dimensions/position
        barCodeDotHeight = 9
        barCodeHeight = 22 * barCodeDotHeight
        barCodeWidth = 22 * barCodeDotHeight
        barCodePosY = int((labelHeight - barCodeHeight) / 2)
        barCodePosX = barCodePosY

        # font dimensions
        sizeLarge = 50
        sizeSmall = 30

        # text positions
        textPosX = 2 * barCodePosX + barCodeWidth
        textPosYFirst = barCodePosY

        fieldSpacing = 5

        offsetY = textPosYFirst

        self.zpl.StartFormat()
        self.zpl.LabelTop(10)
        self.zpl.ChangeInternationalFontEncoding('cp850')
        self.zpl.PrintWidth(labelWidth)

        if 'manufacturerName' in data:
            self.zpl.printText(
                x=textPosX,
                y=offsetY,
                width=550,
                fontWidth=sizeSmall,
                fontHeight=sizeSmall,
                text=data['manufacturerName'])
            offsetY += sizeSmall + fieldSpacing

        pn_font_size = sizeLarge

        meanWidth = sizeLarge * 0.65
        print(len(data['manufacturerPartNumber']))
        if len(data['manufacturerPartNumber']) > 550 / meanWidth:
            pn_font_size = int(
                550 / len(data['manufacturerPartNumber']) / 0.65
            )
            print("font size: %u" % pn_font_size)

        self.zpl.printText(
            x=textPosX,
            y=offsetY,
            width=550,
            fontWidth=pn_font_size,
            fontHeight=sizeLarge,
            text=data['manufacturerPartNumber'])
        offsetY += sizeLarge

        self.zpl.printText(
            x=textPosX,
            y=offsetY,
            width=550,
            fontWidth=sizeSmall,
            fontHeight=sizeSmall,
            text=data['description'],
            maximumNumberOfLines=4)
        offsetY += sizeSmall + fieldSpacing

        self.zpl.printDataMatrixBarCode(
            x=barCodePosX,
            y=barCodePosY,
            height=barCodeDotHeight,
            data=data['id'])

        self.zpl.EndFormat()