GithubHelp home page GithubHelp logo

edinburgh-genome-foundry / blabel Goto Github PK

View Code? Open in Web Editor NEW
160.0 160.0 36.0 7.79 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% HTML 4.56% CSS 5.13%
barcode datamatrix lab-automation label pdf python qrcode

blabel's People

Contributors

drewtchrist avatar veghp avatar zulko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blabel's Issues

Don't force an specific weasyprint version

Hi,

The last version of this lib started to force weasyprint <= 52 due to the fact that not all GNU/Linux distributions have the latest Pango that is required by the latest WeasyPrint.

Although the reasoning is understandable, I think it is too much for blabel to force that, making it impossible for an app that can run weasyprint >= 53 and requires a newer version to use this lib.

I would suggest adding a note on README that if someone have issues with pango, they should fix their weasyprint installation to <=52 and loose this lib's requirement again.

help mimicking an Avery label

I'm trying to mimic an Avery Label for my printer. I'm pretty close but the rest isn't coming together. I think my main issue is the top, bottom, left, right margins and the space down the center. Also, I'm not really sure the labels are 2x4 like the red boxes would have me believe. I don't suppose someone could give me a few hints?

The below creates this: https://i.imgur.com/OFsykvp.png
What I'm going for is this : https://i.imgur.com/k3DFVvn.png

@page {
  width: 8.5in;
  height: 11in;
  padding-top: 12.5mm;
  padding-left: 3mm;
}

img {
  height: 90%;
  display: inline-block;
  vertical-align: middle;
  image-rendering: pixelated;
}
.text {
  font-family: Verdana;
  font-weight: bold;
  vertical-align: middle;
  display: inline-block;
  font-size: 30px;
}
.item {
  width: 4in;
  height: 2in;
  text-align: center;
  border: 1px solid red;
}
<img src="{{label_tools.qr_code(url)}}"/>
<span class='text'>
    BOX <br/>
    LABEL <br/>
    # {{ label_num }} <br/>
</span>

Issues printing labels with multiprocessing

I have a flask application that takes a POST request and then processes some tasks asynchronously - one of these tasks is making and printing a label.

Most of the time it works fine, but occasionally I'll get the error message below when the LabelWriter.write_labels() method is called.

worker = Process(target=async_tasks, daemon=True, args=(data,))
worker.start()

^ This code is called, with the start method set to spawn. This is on macOS 10.15.7, Python 3.7.9.

async_tasks calls several functions, but it consistently errors out on the write_labels method. Restarting apache causes it to work again, but once it starts giving the error, it will persist until apache is restarted.

label_writer = LabelWriter("labels/item_template.html",
                                   default_stylesheets=("labels/style.css",))
records = [
            {'label_text': text, 'url': url}
        ]
print('Writing labels')
label_writer.write_labels(records, target='labels/qrcode_and_label.pdf', base_url='.')

App 66301 output: The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
App 66301 output: Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.

This is happening despite the fact that I'm not using fork as the start method - so presumably something in the write_labels method is forking?

Python Blabel generate broken PDF file

I am writing a program to handle label printing on a thermal transfer printer. I have a problem with corrupted PDF files after generating them with blabel. For example, if I generate a label with the serial number VWAB123456, everything is fine, but in the case of the serial number VWAC123456 a corrupt PDF file is generated.

Damaged PDF after printing with Sumatra PDF looks fine, but bold font disappears and the font type changes. It looks like CSS is not being used at all at the moment. Adobe Reader error below:
Broken PDF
Damagen PDF Image

Label without bold (broken PDF file)
Label without bold

Label with bold (fine PDF)
Label with bold

Python code:
Python code

HTML code:
HTML code

CSS sheet:
CSS sheet

Can anyone help me with this problem?

QR Code is too small to scan with web cam

On the whole, this is an amazing package and creates labels in just the size and format that I need.

My one stumbling block is that the I can scan the QR codes that it creates with my phone camera, but not with the web cam on my PC. Has anyone else mentioned that or found a way to handle it?

Putting multiple elements into QR code

The more I use this package, the more I like it. However I would like to put multiple elements in the QR code.

I've tried these ways without success in the Jinja / image template:

<img src="{{label_tools.qr_code(element_1, element_2, element_3)}}" />

<img src="{{label_tools.qr_code(element_1)}} {{label_tools.qr_code(element_2)}} {{label_tools.qr_code(element_3)}}" />

Is this possible?

Please help me setup blabel.

I tried 2 ways from Visual Studio (still a rookie) & Ananconda Prompt, conda can't install blabel.
My goal is to scan a barcode(ID) and it's look up other columns, names and others details will be printed along with barcode of ID.
Thanks in advance. I just need to setup and able to run the test script is enough.

Adding UTF-8 support

There issue with item_template with Arabic language its show strange character

i solved by edit the blabel.py line93

before
with open(item_template_path) as f:
After
with open(item_template_path, 'r',encoding='utf-8') as f:

i hope there way to determine the encoding by passing argument

Thanks

blabel gives error with pyinstaller

Hi,
I'm developing a python script that print a sticker using blabel package. This script run under ubuntu 2022.
From the VSCode debug, I'm able to run the script and print stickers but when I try to make a single executable file using pyinstaller, launching the executable return the following error :
Traceback (most recent call last): File "python_script.py", line 20, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "blabel/__init__.py", line 5, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "blabel/blabel.py", line 5, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "weasyprint/__init__.py", line 336, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "weasyprint/css/__init__.py", line 25, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "weasyprint/css/computed_values.py", line 10, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "weasyprint/text/line_break.py", line 6, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module File "pyphen/__init__.py", line 33, in <module> FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIRsPxXu/pyphen/dictionaries' [55951] Failed to execute script 'python_script' due to unhandled exception!

But if I generate the executable without the import of blabel package inside the python_script.py, there is no error.
Is there a way to use pyinstaller and blabel without getting any error ?

Thanks in advance,
Antoine

Printing multiple labels

I see in the documentation that it is possible to print two labels sequentially by using two separate dicts.

If I have x number of records in a table and want to loop through them, is it possible to print them on one PDF?

Too long text is silently discarded

With a template like

<img src="{{label_tools.qr_code(label_id)}}"/>
<span class='label'>{{ label_text }}</span>

css style like in README.rst and records like

records= [
...
    dict(label_id="112", label_text="123456789012"),
    dict(label_id="113", label_text="1234567890123"),
    dict(label_id="114", label_text="12345678901234"),
    dict(label_id="115", label_text="123456789012345"),
    dict(label_id="116", label_text="1234567890123456"),
    dict(label_id="117", label_text="12345678901234567"),
    dict(label_id="118", label_text="123456789012345678"),
...

all labels after "12345678901234" only contains the QR code while the text is blank.

One thing is not handling auto-scaling or word splitting, but silently dropping input is really bad. Could you please fix to at least give a warning/error?

QR Codes are shifted!

I have a problem with the qr code generation.
grafik

grafik

As you can see in the two pictures, label one is generated with the correct F 1 number, but the code for the barcode generation is the one from the second label. They are interchanged.

I think this could be also related to my other problem posted earlier.

Anyone an idea?

No Barcode when generating only one Label

I have a problem when generating only one label in the PDF file. If there is only one entry in the records variable, the barcodes / qr codes are not generated anymore..

Does anyone have an idea?

module 'barcode' has no attribute 'get_barcode_class'

Hello,

I can't use blabel with barcode.
with Qr code it's work fine but when i use "<img src="{{label_tools.barcode(sample_id, module_width=1, font_size=50)}}"/>" in my template i have this issue (module 'barcode' has no attribute 'get_barcode_class')

I reinstall with pip install python-barcode but nothing to do, same issue.

python version 3.9.2
django version 3.1.3

Can you add a section of how to install it.

I tried to install the same in Anaconda prompt, the installation went fine but than I ran into the following error when I ran a sample code via Jupyter Notebook.

in
----> 1 from blabel import LabelWriter
2
3 label_writer = LabelWriter("item_template.html", items_per_page=3,
4 default_stylesheets=("style.css",))
5 records= [

C:\ProgramData\Anaconda3\lib\site-packages\blabel_init_.py in
3 # all = []
4
----> 5 from .blabel import LabelWriter
6 from .tools import JupyterPDF

C:\ProgramData\Anaconda3\lib\site-packages\blabel\blabel.py in
4
5 import jinja2
----> 6 from weasyprint import HTML
7 from . import label_tools
8 from . import tools

C:\ProgramData\Anaconda3\lib\site-packages\weasyprint_init_.py in
438
439 # Work around circular imports.
--> 440 from .css import preprocess_stylesheet # noqa isort:skip
441 from .html import ( # noqa isort:skip
442 HTML5_UA_STYLESHEET, HTML5_PH_STYLESHEET, find_base_url, get_html_metadata)

C:\ProgramData\Anaconda3\lib\site-packages\weasyprint\css_init_.py in
28 from ..logger import LOGGER, PROGRESS_LOGGER
29 from ..urls import URLFetchingError, get_url_attribute, url_join
---> 30 from . import computed_values, media_queries
31 from .properties import INHERITED, INITIAL_NOT_COMPUTED, INITIAL_VALUES
32 from .utils import remove_whitespace

C:\ProgramData\Anaconda3\lib\site-packages\weasyprint\css\computed_values.py in
15 from tinycss2.color3 import parse_color
16
---> 17 from .. import text
18 from ..logger import LOGGER
19 from ..urls import get_link_attribute

C:\ProgramData\Anaconda3\lib\site-packages\weasyprint\text.py in
12 import re
13
---> 14 import cairocffi as cairo
15 import cffi
16 import pyphen

C:\ProgramData\Anaconda3\lib\site-packages\cairocffi_init_.py in
48 cairo = dlopen(
49 ffi, ('cairo', 'libcairo-2'),
---> 50 ('libcairo.so', 'libcairo.2.dylib', 'libcairo-2.dll'))
51
52

C:\ProgramData\Anaconda3\lib\site-packages\cairocffi_init_.py in dlopen(ffi, library_names, filenames)
43 error_message = '\n'.join( # pragma: no cover
44 str(exception) for exception in exceptions)
---> 45 raise OSError(error_message) # pragma: no cover
46
47

OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e

Help using Blabel

I've installed Blabel both with pip and by unzipping the source files but I still get an error in python when I try to do a test run. I don't know whats going on. Attached are the errors.

Traceback (most recent call last):
File "C:\Users\DPetit\PycharmProjects\snakeLabels\main.py", line 5, in
from blabel import LabelWriter
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\blabel_init_.py", line 5, in
from .blabel import LabelWriter
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\blabel\blabel.py", line 6, in
from weasyprint import HTML
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\weasyprint_init_.py", line 322, in
from .css import preprocess_stylesheet # noqa isort:skip
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\weasyprint\css_init_.py", line 27, in
from . import computed_values, counters, media_queries
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\weasyprint\css\computed_values.py", line 16, in
from ..text.ffi import ffi, pango, units_to_double
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\weasyprint\text\ffi.py", line 380, in
gobject = _dlopen(
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\weasyprint\text\ffi.py", line 377, in _dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\DPetit\PycharmProjects\AntScan\venv\lib\site-packages\cffi\api.py", line 827, in _load_backend_lib
raise OSError(msg)
OSError: cannot load library 'gobject-2.0-0': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'

Process finished with exit code 1

Cairo library module not loading

missing_module

I get this after running the pip install on Windows 10 console (in administrator mode), and then trying to run the example code provided. Errors seem to indicate dependent libraries are not loading

Unwanted margin on divs/labels

Hi, i just found this library and it is just what i need. I am using it to create several sheets of individual labels form an excel sheet. I currently got it to work, but i have one problem with the html template that i have created.
I cant figure out how to remove the small margin that occurs between each of the stickers on the page. The reason why this is a problem, is because i need to fit exactly 24 labels on one page with the correct margin, width and height - since the labels are gonna be printed on a label sheet paper (this model)

I think that maybe it is some autogenerated margin between each time a label is generated from my html template by blabel, but i do not know.

Here is my template_generate.html

<center>
<div class="label" align="center">
<p class="label_desc">{{sample_name}}</p><img src="{{label_tools.barcode(sample_id, barcode_class='code128', fmt='png', text_distance=1.0, module_height=5.0,quiet_zone=3.0,font_size=7)}}" class="label_img" alt="Could not generate barcode">
</div>
</center>

generate.py

from blabel import LabelWriter
import pandas, time, sys
print("Imported libraries")

skus_file = pandas.read_excel(r'2020_repair_form.xlsx',engine="openpyxl", na_filter=False)
print("Imported SKU file")

label_writer = LabelWriter("template_generate.html", items_per_page=24,
                           default_stylesheets=("style.css",))
print("Created label writer")

print("Generating records")
records = []
for x in range(len(skus_file.SKU)):
    if skus_file.SKU[x] == "":
        continue
    sku = skus_file.SKU[x]
    desc = skus_file.Description[x]
    temp_dict = dict(sample_id=sku, sample_name=desc)
    records.append(temp_dict)
    

print("Generating PDF file")
label_writer.write_labels(records, target='labels_spareparts.pdf')

style.css

* {
    margin: 0mm;
    padding: 0mm;
}
@page {
    width: 193.9mm;
    height: 271mm;
    padding: 13mm 8.1mm 13mm 8.1mm; 
    margin: 0mm;
}

.label {
    font-family: Arial;
    display: inline-block;
    font-size: 12px;
    max-width: 63.3mm;
    max-height: 33.9mm;
    width: 63.3mm;
    height: 33.9mm;
    margin: 0mm;
    padding: 0mm;
    overflow: hidden;
    background-color: green;
}
.label_img {
    image-rendering: pixelated;
    max-width: 85%;
    margin: 0mm;
    padding: 0mm;

}
.label_desc{
    max-width: 80%;
    margin: 0mm auto;
    padding: 0mm;
    
    text-align: center;
    padding-top: 5mm;
    padding-bottom: 3mm

}

The result i get:
image

The white lines indicated with the yellow arrow are unwanted.
image

I have already tried trimming the whitespace and almost everything that i could find, which is why i am asking here now.

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.