A couple of days ago I started to use ReportLab with Python34. It's pretty nice package but I have one big problem that I don't know how to overcome.
Could someone check my code and help me get over this? The problem is connected with letter č in Slovenian language. In the title there is no problem, but later in pdf file I cannot see that letter.
My code is below:
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfgen import canvas
from reportlab.pdfbase.ttfonts import TTFont
styles = getSampleStyleSheet()
Title = "Izračun pokojnine"
def myPage(canvas, doc):
canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, Title)
doc = SimpleDocTemplate("phello.pdf")
Story = [Spacer(1,2*inch)]
style = styles["Normal"]
p = Paragraph(bogustext, style)
The problem is that in the title you are using
Vera as the font, in the text you are using the default font used by Reportlab which is
Times-Roman (if I remember correctly).
The blackboxes you're seeing indicate that the current font (
Times-Roman) doesn't have a symbol for the character you are trying to display. So to fix it you will have to change the font of the text to a font that does contain a symbol for č. One way to do this is by creating a new style Like this:
ParagraphStyle('MyNormal', parent=styles['Normal'], fontName='Vera')
In some cases it might be easier to replace the missing symbols with the symbol form a fallback font in which case you might want to check out this answer I posted earlier this year.