Spaces:
Runtime error
Runtime error
Commit
·
54b4c8b
1
Parent(s):
98a7c2c
Update app.py
Browse files
app.py
CHANGED
@@ -95,18 +95,15 @@ def save_as_pdf(text):
|
|
95 |
'margin-bottom': '0.75in',
|
96 |
'margin-left': '0.75in',
|
97 |
}
|
98 |
-
|
99 |
-
pdfkit.from_string(text, pdf_file, options=options)
|
100 |
-
except OSError as e:
|
101 |
-
st.error("Error generating PDF. Please check if wkhtmltopdf is installed.")
|
102 |
-
return
|
103 |
|
104 |
# encode the PDF to base64
|
105 |
b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
|
106 |
|
107 |
-
# generate
|
108 |
-
|
109 |
-
|
|
|
110 |
|
111 |
|
112 |
|
@@ -224,11 +221,15 @@ def editor_page():
|
|
224 |
new_html = f"""<html><head><style>{css}</style></head><body>{soup}</body></html>"""
|
225 |
|
226 |
# Save the output text as a PDF
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
232 |
|
233 |
# Add some custom CSS to style the editor
|
234 |
st.markdown("""
|
|
|
95 |
'margin-bottom': '0.75in',
|
96 |
'margin-left': '0.75in',
|
97 |
}
|
98 |
+
pdfkit.from_string(text, pdf_file, options=options)
|
|
|
|
|
|
|
|
|
99 |
|
100 |
# encode the PDF to base64
|
101 |
b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
|
102 |
|
103 |
+
# generate the filename
|
104 |
+
filename = 'output.pdf'
|
105 |
+
|
106 |
+
return b64, filename
|
107 |
|
108 |
|
109 |
|
|
|
221 |
new_html = f"""<html><head><style>{css}</style></head><body>{soup}</body></html>"""
|
222 |
|
223 |
# Save the output text as a PDF
|
224 |
+
pdf_data, filename = save_as_pdf(new_html)
|
225 |
+
|
226 |
+
# display a download button for the PDF file
|
227 |
+
st.download_button(
|
228 |
+
label='Download PDF',
|
229 |
+
data=pdf_data,
|
230 |
+
file_name=filename,
|
231 |
+
mime='application/pdf'
|
232 |
+
)
|
233 |
|
234 |
# Add some custom CSS to style the editor
|
235 |
st.markdown("""
|