PDF download of part of the output

Hello all,

I am a novice at Streamlit and this is my first post here.

I’ve created a simple app, which gives users results of calculations based on inputs. and I would like to give user an option to export a PDF of outputs which contains subheader, text and a dataframe.
I’ve seen a print to pdf option in built-in print menu, but it gives the whole page, including inputs and other widgets.

Is there an option to do this?

Here’s an example that generates a pdf and downloads it

import streamlit as st

def generate_pdf():
    """Generate an example pdf file and save it to example.pdf"""
    from fpdf import FPDF

    pdf = FPDF()
    pdf.set_font("Arial", size=12)
    pdf.cell(200, 10, txt="Welcome to Streamlit!", ln=1, align="C")

if st.button("Generate PDF"):
    st.success("Generated example.pdf!")

with open("example.pdf", "rb") as f:
    st.download_button("Download pdf", f, "example.pdf")

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