Regarding Table Generation #619
Unanswered
NikhilExactSpace
asked this question in
Q&A
Replies: 1 comment 4 replies
-
The Here is a full example where those settings are controlled by parameters: from fpdf import FPDF
import pandas as pd
def output_df_to_pdf(pdf, df, cell_width, cell_height):
render_table_header(df, cell_width, cell_height)
for row in df.itertuples():
if pdf.will_page_break(cell_height):
render_table_header(df)
pdf.set_font(style='')
for col in df.columns:
value = str(getattr(row, col))
pdf.cell(cell_width, cell_height, value, align='C', border=1)
pdf.ln(cell_height)
def render_table_header(df, cell_width, cell_height):
pdf.set_font('Arial', 'B', 8)
for col in df.columns:
pdf.cell(cell_width, cell_height, col, align='C', border=1)
pdf.ln(cell_height)
df = pd.DataFrame(
{
"FirstName": ["Jules", "Mary", "Carlson", "Lucas"],
"LastName": ["Smith", "Ramos", "Banks", "Cimon"],
"Age": [34, 45, 19, 31],
"City": ["San Juan", "Orlando", "Los Angeles", "Saint-Mahturin-sur-Loire"],
}
)
pdf = FPDF()
pdf.add_page()
output_df_to_pdf(pdf, df, cell_width=32, cell_height=12)
pdf.output("table_with_cells.pdf") |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There is any method to auto adjust table height and width , if we pass dataset ?
if there any method please let me know.
Beta Was this translation helpful? Give feedback.
All reactions