show-pdf / app.py
lvwerra's picture
lvwerra HF Staff
Update app.py
027467a
raw
history blame contribute delete
878 Bytes
import streamlit as st
import base64
PDF_WIDTH = 700
PDF_HEIGHT = 1000
PDF_PATH = "./some_pdf.pdf"
def display_pdf(file):
# Opening file from file path
with open(file, "rb") as f:
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
# Embedding PDF in HTML
pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="{PDF_WIDTH}" height="{PDF_HEIGHT}" type="application/pdf"></iframe>'
# Displaying File
st.markdown(pdf_display, unsafe_allow_html=True)
st.title("Welcome to PDF viewer 2000!")
st.markdown("## This is a markdown title")
st.markdown("I want to display the _best_ PDF of my **collection**!")
st.markdown("Learn more what a pdf is [here](https://en.wikipedia.org/wiki/PDF).")
st.sidebar.markdown("_Hint_: you can also display things on the sidebar.")
display_pdf(PDF_PATH)
st.markdown("Goodbye")