GithubHelp home page GithubHelp logo

suraphelkd / blabel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edinburgh-genome-foundry/blabel

0.0 0.0 0.0 7.72 MB

:label: Python label/sticker PDF generation. HTML templates, built-in barcodes, qr codes, and other goodies

Home Page: https://edinburgh-genome-foundry.github.io/blabel

License: MIT License

Python 90.31% CSS 5.13% HTML 4.56%

blabel's Introduction

Blabel

GitHub CI build status https://coveralls.io/repos/github/Edinburgh-Genome-Foundry/blabel/badge.svg?branch=master

Blabel Logo

Blabel is a Python package to generate labels (typically for printing stickers) with barcodes and other niceties.

Some features:

  • Generates PDF files where each page is a label (that's the way most label printers want it).
  • Label layout is defined by HTML (Jinja) templates and CSS. Supports any page dimensions and margins.
  • Builtin support for various barcodes, QR-codes, datamatrix, and more (wraps other libraries).
  • Labels data can be provided as list of dicts (easy to generate from spreadsheets).
  • Possibility to print several items per sticker.



Example

To generate labels with Blabel you first need a HTML/Jinja template, and optionally a style sheet, to define how your labels will look like.



HTML item template (item_template.html)

Notice the use of label_tools (Blabel's builtin features). The variables sample_name and sample_id will be defined at label creation time.

<img src="{{label_tools.qr_code(sample_id)}}"/>
<span class='label'>
    {{ sample_name }} <br/>
    Made with blabel <br/>
    {{ label_tools.now() }}
</span>


CSS stylesheet (style.css)

Notice the CSS @page attributes which allows you to adjust the page format to the dimensions of your sticker. Also notice the pixelated image rendering. If your printer is black/white only with no greyscale support, this option will ensure crisp-looking barcodes, qr codes, etc.

@page {
    width: 27mm;
    height: 7mm;
    padding: 0.5mm;
}
img {
    height: 6.4mm;
    display: inline-block;
    vertical-align: middle;
    image-rendering: pixelated;
}
.label {
    font-family: Verdana;
    font-weight: bold;
    vertical-align: middle;
    display: inline-block;
    font-size: 7px;
}


Python code

In your Python script, create a LabelWriter linked to the two files above, and feed it a list of of dicts ("records"), one for each label to print:

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_label.pdf')


Result:

Blabel Logo

Other examples

Installation

You can install Blabel via PIP:

pip install blabel

Alternatively, you can unzip the sources in a folder and type:

python setup.py install

Note: the package depends on the WeasyPrint Python package. If there are any issues, see installation instructions in the WeasyPrint documentation.

If you have an older GNU/Linux distribution (e.g. Ubuntu 18.04), then install an older WeasyPrint (<=52), as they don't have the latest Pango that is required by the latest WeasyPrint: pip install weasyprint==52

Note: on macOS, you may need to first install pango with brew install pango.

Note: on some Debian systems you may need to first install libffi-dev (apt install libffi-dev). The package name may be libffi-devel on some systems.

License = MIT

DnaChisel is an open-source software originally written at the Edinburgh Genome Foundry by Zulko and released on Github under the MIT licence (Copyright 2018 Edinburgh Genome Foundry). Everyone is welcome to contribute!

More biology software

https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Edinburgh-Genome-Foundry.github.io/master/static/imgs/logos/egf-codon-horizontal.png

Blabel was originally written to print labels for biological samples and is part of the EGF Codons synthetic biology software suite for DNA design, manufacturing and validation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.