Sep-10-2020, 04:57 AM
(Mar-20-2019, 07:36 AM)hiroz Wrote: It's working! It turned out that under registering the fonts, here is this row:
pdfmetrics.registerFont(TTFont('FreeSans', 'FreeSans.ttf'))It picks up the font from the folder from which it is launched. This font wasn't there, so it didn't work. Why does it output Russian strings using DrawString when there is no font in the folder is a good question, but I have no answer. Here is an example of working code:
from reportlab.lib import colors from reportlab.lib.pagesizes import letter from reportlab.platypus import SimpleDocTemplate, Table, TableStyle from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont def table_fonts(): doc = SimpleDocTemplate("table_fonts.pdf", pagesize=letter) story = [] data = [['ф_{}'.format(x) for x in range(1, 6)], ['фф', 'ф', 'ф', 'ф', 'ф'] ] tblstyle = TableStyle([('FONT', (0, 0), (-1, 1), 'DejaVuSerif', 24) ]) tbl = Table(data) tbl.setStyle(tblstyle) story.append(tbl) doc.build(story) if __name__ == '__main__': pdfmetrics.registerFont(TTFont('DejaVuSerif', 'DejaVuSerif.ttf')) table_fonts()make sure that the “DejaVuSerif.ttf" is in the folder next to the file. All the blessings
GOD BLESS YOU!!!



I tried for a couple of days without any resuts until I found your post.
I was trying to make(and in the end I managed to make)a software that can make a simple packaging label with ean13 barcode, title (translated in 4 languages with google translate), other specs and logo on it.
I had to make around 700 labels very quick because the truck was waiting at the warehouse, the products could be received because they camed without proper labels....so....being a graphic designer with few friends working in the coding area I started to make a python soft/script.
I managed to make the software but because I had bulgarian and maghiar languages, It was giving me black squares instead of letters...
So here YOU come and save my day and the truck drivers day! After staying at the warehouse waiting for my labels to land the products..
Real life story!! :)