Edinburgh-Genome-Foundry / blabel

:label: Python label/sticker PDF generation. HTML templates, built-in barcodes, qr codes, and other goodies
https://edinburgh-genome-foundry.github.io/blabel
MIT License
179 stars 38 forks source link

How to create multiline label with name at the bottom #5

Closed noppGithub closed 3 years ago

noppGithub commented 4 years ago

I want to create labels with the following contents. Is it possible to do ?

52/3 Avenue road,
Chumpo district,
Lamgo province 19456
                                          <John Saverilo>
veghp commented 4 years ago

There are many ways to do it; for example edit style.css to resize label and add "right" class:

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

And the template html:

<img src="{{label_tools.qr_code(sample_id)}}"/>
<span class='label'>
    {{ sample_name }} <br/>
    52/3 Avenue road, <br/>
    Chumpo district, <br/>
    Lamgo province 19456 <br/>
    <span class="right">&lt;John Saverilo&gt;</span>
</span>

label

For more customization, see the online documentations on html and css.

noppGithub commented 4 years ago

@veghp

Thank you so much for the prompt response, your solution is working. But I still need to add 2 options.

My current code is below, and the current result is attached, I want to put all the labels in a single A4 page(s) Files:

my_blabel.py

from blabel import LabelWriter
import pandas

df = pandas.read_excel("file.xlsx")
df = df.iloc[:100,:]
records = df.to_dict(orient="records")

label_writer = LabelWriter("item_template.html", default_stylesheets=("style.css",))

label_writer.write_labels(records, target="labels_from_spreadsheet.pdf")

style.css

@page {
    width: 297mm;
    height: 420mm;
    padding: 4.5mm;
}
img {
    height: 6.4mm;
    display: inline-block;
    vertical-align: middle;
    image-rendering: pixelated;
}
.label {
    font-family: Ubuntu;
    font-weight: bold;
    vertical-align: middle;
    display: inline-block;
    font-size: 7px;
}
.right{
    float:right;
}

item_template.html

<span class='label'>
    {{ FIRST_NAME }} {{ SURNAME }} <br/>
    {{ ADDLINE1 }}, <br/>
    {{ ADDLINE2 }}, <br/>
    {{ ADDLINE3 }} {{ ZIPCODE }} <br/>
    <span class="right">&lt;{{ ID_NUM }}&gt;</span>
</span>
veghp commented 4 years ago

To change the font, replace "Ubuntu" in the css file with the font that you want to use and is installed on the system.

Putting multiple items on a page is covered in the examples, see the Python and css files in this folder: https://github.com/Edinburgh-Genome-Foundry/blabel/tree/master/examples/several_items_per_page Let me know if this solves the problem.

noppGithub commented 4 years ago

@veghp Thanks so much, after reading your guide + some tweaks, now my task is done.

noppGithub commented 3 years ago

Resolution is valid and tested