Spaces:
Runtime error
Runtime error
File size: 1,789 Bytes
ee83c82 dfe3c39 ee83c82 dfe3c39 ee83c82 dfe3c39 a18878f dfe3c39 ee83c82 a18878f ee83c82 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
from meutils.pipe import *
from appzoo.streamlit_app import Page
import streamlit as st
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"""<embed src="data:application/pdf;base64,{base64_pdf}" width="{width}" height="{height}" type="application/pdf">"""
# data_type = 'vnd.openxmlformats-officedocument.wordprocessingml.document'
# pdf_display = f"""<embed src="data:application/{data_type};base64,{base64_pdf}" width="{width}" height="{height}" type="application/{data_type}">"""
st.markdown(pdf_display, unsafe_allow_html=True)
def display_html(self, text='会飞的文字'):
_ = f"""
<marquee direction="down" width="100%" height="100%" behavior="alternate" style="border:solid" bgcolor="#00FF00">
<marquee behavior="alternate">
{text}
</marquee>
</marquee>
"""
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()
|