def generate_barcode_label(self): from blabel import LabelWriter label_writer = LabelWriter( "barcode_template.html", default_stylesheets=("barcode_style.css",), ) records = [self.barcode_record] return label_writer.write_labels(records, target=None)
def render_to_file(self, filename, items, **kwargs): """ Render labels to a PDF file """ records = self.get_record_data(items) writer = LabelWriter(self.template) writer.write_labels(records, filename)
def generate_label(products, filename): from blabel import LabelWriter label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css", )) records = [ dict(sample_id="s01", sample_name="Sample 1"), dict(sample_id="s02", sample_name="Sample 2") ] label_writer.write_labels(products, target=filename + '.pdf', base_url='.')
def render(self, items, **kwargs): """ Render labels to an in-memory PDF object, and return it """ records = self.get_record_data(items) writer = LabelWriter(self.template) buffer = io.BytesIO() writer.write_labels(records, buffer) return buffer
def writeLabels(excelFile, templateFile, stylesheet=None): assets = list() try: dataframe = pandas.read_excel(excelFile, dtype='str') except: print("Unknown Exception: Failed to load spreadsheet.") return False records = dataframe.to_dict(orient='record') label_writer = LabelWriter(templateFile, default_stylesheets=(stylesheet)) label_writer.write_labels(assets, target="export.pdf") return True
from blabel import LabelWriter label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css", )) records = [ dict(sample_id="s01", sample_name="Sample 1"), dict(sample_id="s02", sample_name="Sample 2"), ] label_writer.write_labels(records, target="qrcode_and_date.pdf")
from blabel import LabelWriter import pydenticon import base64 def generate_identicon(sample_id): identicon_generator = pydenticon.Generator( 6, 6, foreground=['red', 'blue', 'green', 'purple']) img = identicon_generator.generate(sample_id, 60, 60) return 'data:image/png;base64,%s' % (base64.b64encode(img).decode()) label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css", ), generate_identicon=generate_identicon) records = [ dict(sample_id="s01", sample_name="Sample 1"), dict(sample_id="s02", sample_name="Sample 2"), dict(sample_id="s03", sample_name="Sample 3") ] label_writer.write_labels(records, target='barcode_and_dynamic_picture.pdf')