Spaces:
Runtime error
Runtime error
amoldwalunj
commited on
Commit
•
98a7c2c
1
Parent(s):
a9f4735
Update app.py
Browse files
app.py
CHANGED
@@ -95,7 +95,11 @@ def save_as_pdf(text):
|
|
95 |
'margin-bottom': '0.75in',
|
96 |
'margin-left': '0.75in',
|
97 |
}
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
|
100 |
# encode the PDF to base64
|
101 |
b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
|
@@ -106,7 +110,6 @@ def save_as_pdf(text):
|
|
106 |
|
107 |
|
108 |
|
109 |
-
|
110 |
def form_page():
|
111 |
|
112 |
st.markdown("### Your custom obituary writer :pencil:")
|
@@ -221,8 +224,11 @@ def editor_page():
|
|
221 |
new_html = f"""<html><head><style>{css}</style></head><body>{soup}</body></html>"""
|
222 |
|
223 |
# Save the output text as a PDF
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
226 |
|
227 |
# Add some custom CSS to style the editor
|
228 |
st.markdown("""
|
|
|
95 |
'margin-bottom': '0.75in',
|
96 |
'margin-left': '0.75in',
|
97 |
}
|
98 |
+
try:
|
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')
|
|
|
110 |
|
111 |
|
112 |
|
|
|
113 |
def form_page():
|
114 |
|
115 |
st.markdown("### Your custom obituary writer :pencil:")
|
|
|
224 |
new_html = f"""<html><head><style>{css}</style></head><body>{soup}</body></html>"""
|
225 |
|
226 |
# Save the output text as a PDF
|
227 |
+
try:
|
228 |
+
save_as_pdf(new_html)
|
229 |
+
st.write("The custom obituary has been saved as a PDF.")
|
230 |
+
except Exception as e:
|
231 |
+
st.error("Error saving PDF. " + str(e))
|
232 |
|
233 |
# Add some custom CSS to style the editor
|
234 |
st.markdown("""
|