def _write_product_table_row(self, work_book, work_sheet, product, line, percent_top): writer = ImageWriter() writer.set_options({ 'font_size': 18, 'text_distance': 2, 'quiet_zone': 2 }) ean = barcode.get('ean13', product.barcode, writer=writer) file_name = ean.save('barcode', { 'quiet_zone': 2, 'text_distance': 2, 'module_height': 8 }) size = openpyxl.drawing.Image(file_name).image.size * array( [0.35, 0.35]) img = openpyxl.drawing.Image(file_name, size=size) line_number = 'A%s' % line img.anchor(work_book.worksheets[0].cell(line_number)) img.drawing.top = percent_top work_sheet.append(( product.barcode, product.name, product.order, product.quantity, )) row = self._get_last_row(work_sheet) row.alignment = self.metadata_style work_sheet.append((work_sheet.add_image(img), )), return img.drawing.top
def print_info(document, categories=None): """Print report info page.""" if categories is None: categories = {} if document["category"]: current_category = categories[document["category"]] cat_list = [current_category] while current_category["parent"]: cat_list.insert(0, categories[current_category["parent"]]) current_category = categories[current_category["parent"]] else: cat_list = [] printer.set(font="a", align="center") printer.text("DOCUMENTO - Archivetikett\n") printer.set(font="a", double_height=True, align="right", underline=False) printer.text("NR. {}\n".format(document["id"])) printer.set(font="b", align="left") printer.text("Titel:\n") printer.set(font="a", double_height=True, align="left", underline=True) printer.textln(document["name"]) printer.set(font="b", align="left") printer.text("Zeitpunkt der Archivierung:\n") printer.set(font="a", double_height=False, align="left", underline=False) printer.textln(document["added_at"]) printer.set(font="b", align="left") printer.text("Kategorie:\n") printer.set(font="a", double_height=False, align="center", underline=False) cat_names = ["[" + cat["name"] + "]\n" for cat in cat_list] printer.text("V\n".join(cat_names)) printer.set(font="b", align="left") printer.text("Barcode:\n") barcode = document["barcode"] writer = ImageWriter() writer.set_options( {"module_width": 0.4, "module_height": 5.0, "text_distance": 3.0} ) code = Code128(barcode, writer=writer).render() printer.image(code, center=True) printer.ln(3) printer.control("LF")
def generate_barcode(event): global tmp_path delete_temp_image() barcode_txt = ent_barcode_txt.get() code_type = ent_code_type.get() if len(barcode_txt) is 0: notify('Nothing to do') return print(f'Code type: {code_type}') print(f'Text to generate: {barcode_txt}') b_class = barcode.get_barcode_class(code_type) iw = ImageWriter() iw.set_options({'dpi': 140}) try: bar = b_class(str(barcode_txt), writer=iw) notify('Format success') except (barcode.errors.WrongCountryCodeError, barcode.errors.BarcodeError, barcode.errors.BarcodeNotFoundError, barcode.errors.IllegalCharacterError, barcode.errors.NumberOfDigitsError, ValueError) as e: return notify(str(e)) path = os.path.join(tempfile.gettempdir(), barcode_txt) tmp_path = bar.save(path, text=barcode_txt) print(f'temporary image: {tmp_path}')
'text_distance': 3 } optionsPng = { 'module_height': 10, # 'quiet_zone': 10, 'font_size': 15, 'text_distance': 1 } imgWriter = ImageWriter() options = optionsPng # options = optionsSvg # imgWriter = None #using with svg imgWriter.set_options(options) EAN = barcode.get( 'code128', options=options, ) def run(saveDir, text): print(text) ean = EAN(text, writer=imgWriter) fullname = ean.save(saveDir + text, options=options) def main(): filename = 'input.txt' with open(filename, 'r') as f:
def makeTag(serialNum, assetTag, outputfile): """ create a single image with two barcodes in it sized for individual labels, 62mmx28mm """ if (serialNum is None) and (assetTag is None): raise Exception("must provide at least one value for label") code39 = barcode.get_barcode_class('code39') twoBarcodes = (serialNum is not None) and (assetTag is not None) wrt = ImageWriter() label = (696, 271) #pixels for a 62mmx28mm label margin = 3 #mm width = px2mm(label[0]) - 2 * margin #showable width in mm if twoBarcodes: modHeight = 7 # bardcode height else: modHeight = 14 #code39 5 bars, 4 spaces per symbol. 3 wide, 6 narrow, 3:1 ratio #settings for the Serial number #resize the width of a line to make them fit in the printable width #16 modules per symbol if serialNum is not None: a = code39(serialNum, add_checksum=False) wrt.set_options({ 'text': 'SN: ' + a.code, 'text_distance': 0.5, 'quiet_zone': 0, 'module_height': modHeight, 'module_width': width / ((2 + len(a.get_fullcode())) * 16) }) apil = wrt.render(a.build()) else: apil = fake() apil.size = (0, 0) if assetTag is not None: b = code39(assetTag, add_checksum=False) #settings for the Asset Tag wrt.set_options({ 'text': 'TAG: ' + b.code, 'text_distance': 0.5, 'quiet_zone': 0, 'module_height': modHeight, 'module_width': width / ((2 + len(b.get_fullcode())) * 16) }) bpil = wrt.render(b.build()) else: bpil = fake() bpil.size = (0, 0) #print (apil.size) #print (bpil.size) if (apil.size[1] + bpil.size[1]) > label[1]: raise Exception("images dont fit") #create a custom canvas of the correct size #paste both barcodes into it, aproximately centered im = Image.new('RGB', label, 'white') top = int((label[1] - (apil.size[1] + bpil.size[1])) / 2) left = int((label[0] - apil.size[0]) / 2) if serialNum is not None: im.paste(apil, (0 + left, top, apil.size[0] + left, top + apil.size[1])) left = int((label[0] - bpil.size[0]) / 2) if assetTag is not None: im.paste(bpil, (0 + left, top + apil.size[1], bpil.size[0] + left, top + apil.size[1] + bpil.size[1])) im.save(outputfile, 'PNG')
def _write_product_table_row(self, work_book, work_sheet, product, line, percent_top): writer = ImageWriter() writer.set_options({"font_size": 18, "text_distance": 2, "quiet_zone": 2}) ean = barcode.get("ean13", product.barcode, writer=writer) file_name = ean.save("barcode", {"quiet_zone": 2, "text_distance": 2, "module_height": 8}) size = openpyxl.drawing.Image(file_name).image.size * array([0.35, 0.35]) img = openpyxl.drawing.Image(file_name, size=size) line_number = "A%s" % line img.anchor(work_book.worksheets[0].cell(line_number)) img.drawing.top = percent_top work_sheet.append((product.barcode, product.name, product.order, product.quantity)) row = self._get_last_row(work_sheet) row.alignment = self.metadata_style work_sheet.append((work_sheet.add_image(img),)), return img.drawing.top