I am creating a program that generates a translation sheet for a language. It uses the python FPDF module. I utilise pdf.multicell()
to create a page with two columns for the English word, and then the foreign equivalent
I am using pdf.set_auto_page_break()
to create a new page whenever I reach the page limit. However, I am experiencing some problems with this.
The new page is always created after one line has been written on a new page. This means that I have mismatched translations, and lots of empty whitepsace.
This is my code:
data = [['le bus', 'the bus'], ['le train', 'the train'], ['la gare', 'the train station']] etc
def write_to_pdf(data):
pdf = FPDF()
pdf.set_auto_page_break(True, 2)
pdf.add_page()
pdf.add_font('DejaVu', '', 'filepath/font', uni=True)
pdf.set_font('DejaVu', '', 14)
pdf.cell(200, 10, txt = title,ln = 1, align = 'C')
pdf.cell(200, 10, txt = subtitle,ln = 2, align = 'C')
pdf.set_font('DejaVu', '', 10)
for section in data:
try:
top = pdf.y
offset = pdf.x + 100
pdf.multi_cell(100,10,section[0],0,'L')
pdf.y = top
pdf.x = offset
pdf.multi_cell(100,10,section[1],0,'R')
except:
pass
pdf.output("Output.pdf")
And this is the result
Thank you in advance for any help