@ash2shukla please can you help me save a dataframe to pdf using streamlit I really need it
Thank you for your answer I will look to it
Looks like fpdf doesn’t work for Python 3.6 and later. Any other solution?
@ash2shukla Is streamlit dev community thinking of adding the functionality to directly export streamlit app page to pdf without the need to individually add elements? I and many others won’t agree much to “Though streamlit doesnt support PDF generation out of the box for obvious reasons”
I agree Sharman - there was a thread I’d started on this a year or two ago; it’s easy to ‘print’ as PDF from a local deployment but on streamlit sharing that functionality does not work. It would be excellent to be able to output the currents streamlit app to a PDF using a button.
Hi,
i am trying to use proposed solution, however am getting and encoding error:
AttributeError: ‘bytearray’ object has no attribute ‘encode’
Traceback:
File "D:\Coding\HockeyPlatform\hockeyEnv\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script
exec(code, module.__dict__)File "D:\Coding\HockeyPlatform\pages\5_Prints.py", line 46, in <module>
html = create_download_link(pdf.output(dest="S").encode("latin-1"), "test")
the code I am using:
def create_download_link(val, filename):
b64 = base64.b64encode(val) # val looks like b’…’
return f’<a href=“data:application/octet-stream;base64,{b64.decode()}” ’
f’download=“{filename}.pdf”>Download PDF’
if export_as_pdf:
pdf = PdfReportGenerator(game_name='testGame')
pdf.set_font("courier", size=12)
pdf.add_page()
pdf.cell(200, 10, txt="Welcome to Python!", ln=1, align="C")
html = create_download_link(pdf.output(dest="S").encode("latin-1"), "test")
st.markdown(html, unsafe_allow_html=True)
any help would be appreciated
Hello is there a way to download the whole streamlit page as pdf?
you can use “print” option in the top right menu bar. and “save as pdf”.
Alternatively, you can use any chrome extension that can take a page screenshot and save as pdf. I have used GoFullPage.
replace html = create_download_link(pdf.output(dest="S").encode("latin-1"), "test")
with html = create_download_link(pdf.output(dest="S"), "test")