Table data on streamlit facing problem on download as pdf

Summary

Share a clear and concise description of the issue. Aim for 2-3 sentences.

Steps to reproduce

Code snippet:

add code here

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

Debug info

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version:
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.

Links

  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.
df = data.to_dict(orient=“records”)
def convert_csv_to_pdf(df):
pdf = FPDF()
pdf.add_page()
pdf.set_font(“Arial”, size = 12)

# Add data to PDF
for row in df:
    pdf.cell(200, 10, f"Organ: {row['organ.']}", ln=True)
    pdf.cell(200, 10, f"Month: {row['month']}", ln=True)
    pdf.cell(200, 10, f"Room Category: {row['Room Category']}", ln=True)
    pdf.cell(200, 10, f"RM Nights: {row['RM Nights']}", ln=True)
    pdf.cell(200, 10, f"Revenue: {row['Revenue']:.2f}", ln=True)
    pdf.cell(200, 10, f"ARR: {row['ARR']:.2f}", ln=True)
    pdf.ln()

Convert CSV data to PDF

if st.button(“Generate PDF”):
convert_csv_to_pdf(df)

    st.success("PDF generated successfully!")

st.download_button(label=“Download PDF”, data=“data.pdf”, file_name=“data.pdf”)
this code and its download pdf but not show data showing something went wrong how to resolve this.

Hi @kush_shukla

Looking through your code, it seems you have not defined mime parameter in the st.download_button. Please refer to the following example code snippet:

import streamlit as st

with open("dummy.pdf", "rb") as pdf_file:
    PDFbyte = pdf_file.read()

st.download_button(label="Export_Report",
                    data=PDFbyte,
                    file_name="test.pdf",
                    mime='application/octet-stream')

The above snippet is from this forum post: Download PDF option - #2 by andfanilo

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.