'How do I get Python to not add excessive spacing when I convert to PDF
I'm trying to get my pdf to look more nice and neet like the first picture and less like the second
This is how I'm trying to get it to look like
This is how it currently looks
myFoodsDF = pd.read_sql(getQuery(), conn)
print(myFoodsDF.info())
print(myFoodsDF)
pdf = FPDF()
pdf.add_page()
spacing = 1
col_width1 = pdf.w / 4.5
pdf.set_font("Arial", size=15)
row_height = pdf.font_size
pdf.cell(0, row_height*spacing, txt='Foods and Recipies', border=0, align='C', ln=1)
groupedDF = myFoodsDF.groupby(['Food'])['Recipe'].agg(', '.join)
print(groupedDF[0])
for row in groupedDF.iteritems() :
pdf.set_font("Arial", size=12)
pdf.multi_cell(col_width1, row_height*spacing, txt=row[0].strip(), border=1, align='L')
pdf.set_font("Arial", size=10)
pdf.multi_cell(0, row_height*spacing, txt=row[1].strip(), border=1, align='L')
pdf.ln(row_height*spacing)
pdf.output("Foods.pdf")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
