python-barcode icon indicating copy to clipboard operation
python-barcode copied to clipboard

text above the barcode

Open blutme opened this issue 6 years ago • 1 comments

Hello, I would like to know if there is the possibility of put a text above the bar code?

text here ||IIIIIIllllllllII|| 12345679

Thanks for your help.

blutme avatar Sep 22 '19 02:09 blutme

I think that would mean altering the code. I have found how to alter the default text under the barcode, by adding text= to the save method, such as

image.save(path, text='text here')

But that replaces the default text (the value of the barcode). I got around this by creating a text variable that includes the info I wanted - first name and last name of a user - as well as the barcode by doing this (i'm using objects which have a barcode attribute as well as first_name and last_name):

text = f'{obj.first_name} {obj.last_name.upper()} - {obj.barcode}'

and then passing that to the barcode writer as so:

image.save(path, text=text)

I know that's not exactly what you're looking for, but I hope that helps in the meantime.

djaychela avatar Sep 26 '19 11:09 djaychela