Reputation: 31
I am trying to write a python program for pdf invoice creation. The text lines i write into a newly generated PDF are in Slovene with characters like č, š, ž, etc. which are found in the latin-2 alphabet.
pdf = canvas.Canvas(...)
pdf.setFont("Helvetica", 3)
for line in receipt_lines:
textobject.textLine(line.rstrip())
pdf.drawText(textobject)
The above code correctly generates a pdf, however some of the latin-2 characters (mainly 'č') are instead replaced by black squares. For example, the line: "Račun je bil uspešno nastisnjen" will apear as "Ra~un je bil uspešno natisnjen" where ~ is indicative of a plain black box in the final pdf.
I understand that the encoding with the ReportLab library is a bit finnicky, however I do not understand why only some of the latin-2 special characters are written into the pdf incorrectly.
Upvotes: 1
Views: 37
Reputation: 31
I have now figured out the problem. If you wish to generate PDF's with Latin-2 characters, download a font (.ttf or any other file format supported by ReportLab) which includes Latin-2 characters, as ReportLab doesn't offer any by default.
Upvotes: 2