from meutils.pipe import * from appzoo.streamlit_app import Page import streamlit as st import streamlit.components.v1 as components class MyPage(Page): """ https://zhuanlan.zhihu.com/p/518115802?utm_medium=social&utm_oi=1290068536690085888 """ def main(self): with st.form("PDF"): file = st.file_uploader("选择待上传的PDF文件", type=['pdf', 'docx', 'xlsx']) if st.form_submit_button('开始预览', help='先上传文件!!!'): if file is not None: base64_pdf = base64.b64encode(file.read()).decode('utf-8') self.display_pdf(base64_pdf, width='100%', height=1000) self.display_html() def display_pdf(self, base64_pdf, width='100%', height=1000): # https://blog.51cto.com/laok8/2395498 pdf_display = f"""""" # data_type = 'vnd.openxmlformats-officedocument.wordprocessingml.document' # pdf_display = f"""""" st.markdown(pdf_display, unsafe_allow_html=True) def display_html(self, text='会飞的文字'): _ = f""" {text} """ st.markdown(_, unsafe_allow_html=True) if __name__ == '__main__': app_title = "# PDF应用" app_info = "PDF预览" MyPage( app_title=app_title, app_info=app_info, sidebar_title=None, ).main()