Spaces:
Sleeping
Sleeping
File size: 754 Bytes
103ce4f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from base64 import b64encode
from fpdf import FPDF
import streamlit as st
st.title("Demo of fpdf2 usage with streamlit")
@st.cache_data
def gen_pdf():
pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=24)
pdf.cell(w=40,h=10,border=1,txt="hello world")
return pdf.output(dest='S').encode('latin1')
# Embed PDF to display it:
base64_pdf = b64encode(gen_pdf()).decode("utf-8")
pdf_display = f'<embed src="data:application/pdf;base64,{base64_pdf}" width="700" height="400" type="application/pdf">'
st.markdown(pdf_display, unsafe_allow_html=True)
# Add a download button:
st.download_button(
label="Download PDF",
data=gen_pdf(),
file_name="file_name.pdf",
mime="application/pdf",
) |