Spaces:
Configuration error
Configuration error
import io | |
from fpdf import FPDF | |
def export_to_csv(df): | |
return df.to_csv(index=False).encode("utf-8") | |
def export_to_pdf(df): | |
pdf = FPDF() | |
pdf.add_page() | |
pdf.set_font("Arial", size=10) | |
col_width = pdf.w / (len(df.columns) + 1) | |
row_height = 6 | |
# Header | |
for col in df.columns: | |
pdf.cell(col_width, row_height, str(col), border=1) | |
pdf.ln(row_height) | |
# Data rows | |
for _, row in df.iterrows(): | |
for item in row: | |
pdf.cell(col_width, row_height, str(item), border=1) | |
pdf.ln(row_height) | |
pdf_output = io.BytesIO() | |
pdf.output(pdf_output) | |
return pdf_output.getvalue() |