Closed mangoez closed 2 years ago
There is an example in the documentation that could help you: https://pyfpdf.github.io/fpdf2/Tables.html#using-cells
A useful parameter here is max_line_height
.
There is some starting point code based on what you shared:
from fpdf import FPDF
import pandas as pd
detail_dict = {
"Pipeline ID": "12345",
"Date": "31/12/1999",
"Description": "Meep morp, shoot zappy bois into noggin for science",
"Dataset": "MNE default finger tapping dataset"
}
detail_col = ["Detail", "Description"]
detail_df = pd.DataFrame(list(zip(list(detail_dict.keys()), list(detail_dict.values()))), columns=detail_col)
detail_df.head()
pdf = FPDF()
pdf.add_page()
pdf.set_font('Helvetica', 'B', 8)
table_cell_width = pdf.epw / detail_df.shape[1]
table_cell_height = pdf.font_size * 2.5
cols = detail_df.columns
for col in cols:
pdf.cell(table_cell_width, table_cell_height, col, border=1)
pdf.ln(table_cell_height)
pdf.set_font('Helvetica', '', 10)
for row in detail_df.itertuples():
for col in cols:
line = str(getattr(row, col))
pdf.multi_cell(table_cell_width, table_cell_height, line, border=1,
new_x="RIGHT", new_y="TOP", max_line_height=pdf.font_size)
pdf.ln(table_cell_height)
pdf.output('issue_473.pdf')
Does that solve your issue?
@mangoez: are you still facing this problem? Do you still have questions / need help or can this issue be closed?
Hi @Lucas-C thank you for your assistance! All good :)
I tried stack overflow but to no avail, this is probably not a bug but I couldn't find any other way to fix the issue. All I want to automatic raw height and text wrapping! Please let me know what I can do, cheers.
Here is a reproducible example and what it outputs: