Hello! I want to use Cyrillic in tables, but reportlab outputs black squares instead of characters. Here is an example code:
Python 3.5.3, reportlab 3.5.13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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([( 'TEXTFONT' , ( 0 , 0 ), ( 0 , 1 ), 'FreeSans' ) ]) tbl = Table(data) tbl.setStyle(tblstyle) story.append(tbl) doc.build(story) if __name__ = = '__main__' : pdfmetrics.registerFont(TTFont( 'FreeSans' , 'FreeSans.ttf' )) table_fonts() |