Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import markdown
|
| 3 |
+
from xhtml2pdf import pisa
|
| 4 |
+
import io
|
| 5 |
+
|
| 6 |
+
stitle = st.sidebar.title("Markdown to PDF")
|
| 7 |
+
size_exp = st.sidebar.expander("Text Size", expanded=False)
|
| 8 |
+
name_exp = st.sidebar.expander("File Name", expanded=True)
|
| 9 |
+
with size_exp:
|
| 10 |
+
size = st.text_input("Text Size", value="15", label_visibility="hidden", key="size")
|
| 11 |
+
with name_exp:
|
| 12 |
+
name = st.text_input("File Name", value="markdown", label_visibility="hidden", key="file_name")
|
| 13 |
+
|
| 14 |
+
markdown_text = st.text_area('Enter your Markdown Text Here', height=700, label_visibility="hidden", key="markdown_text")
|
| 15 |
+
|
| 16 |
+
generate_btn = st.button('Generate PDF')
|
| 17 |
+
if generate_btn:
|
| 18 |
+
html = markdown.markdown(markdown_text)
|
| 19 |
+
html = '<style>body { font-size: 'f'{size}''px; }</style>' + html
|
| 20 |
+
pdf = io.BytesIO()
|
| 21 |
+
pisa.CreatePDF(io.StringIO(html), pdf)
|
| 22 |
+
pdf.seek(0)
|
| 23 |
+
st.sidebar.download_button("Download Markdown File", pdf, f'{name}.pdf')
|