Spaces:
Runtime error
Runtime error
Commit
·
d08f561
1
Parent(s):
bd95fa4
Update app.py
Browse files
app.py
CHANGED
@@ -85,9 +85,10 @@ from bs4 import BeautifulSoup
|
|
85 |
import pdfkit
|
86 |
|
87 |
def save_as_pdf(text):
|
88 |
-
#
|
89 |
pdf_file = BytesIO()
|
90 |
options = {
|
|
|
91 |
'page-size': 'Letter',
|
92 |
'margin-top': '0.75in',
|
93 |
'margin-right': '0.75in',
|
@@ -205,20 +206,22 @@ def editor_page():
|
|
205 |
quill_text = st.session_state.output_text
|
206 |
edited_text = st_quill(quill_text)
|
207 |
|
208 |
-
# Extract the HTML and CSS content from the quill editor
|
209 |
-
soup = BeautifulSoup(edited_text['html'], 'html.parser')
|
210 |
-
style_tag = soup.new_tag('style')
|
211 |
-
style_tag.string = edited_text['css']
|
212 |
-
soup.head.append(style_tag)
|
213 |
-
html_content = str(soup)
|
214 |
-
|
215 |
st.write("Here is the edited obituary:")
|
216 |
-
|
217 |
-
st.session_state.edited_text = html_content
|
218 |
|
219 |
if st.button("Save as PDF"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
# Save the output text as a PDF
|
221 |
-
save_as_pdf(
|
222 |
st.write("The custom obituary has been saved as a PDF.")
|
223 |
|
224 |
# Add some custom CSS to style the editor
|
@@ -240,6 +243,7 @@ def editor_page():
|
|
240 |
</style>
|
241 |
""", unsafe_allow_html=True)
|
242 |
|
|
|
243 |
|
244 |
|
245 |
|
|
|
85 |
import pdfkit
|
86 |
|
87 |
def save_as_pdf(text):
|
88 |
+
# create a PDF from the HTML content
|
89 |
pdf_file = BytesIO()
|
90 |
options = {
|
91 |
+
'quiet': '',
|
92 |
'page-size': 'Letter',
|
93 |
'margin-top': '0.75in',
|
94 |
'margin-right': '0.75in',
|
|
|
206 |
quill_text = st.session_state.output_text
|
207 |
edited_text = st_quill(quill_text)
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
st.write("Here is the edited obituary:")
|
210 |
+
st.session_state.edited_text = edited_text
|
|
|
211 |
|
212 |
if st.button("Save as PDF"):
|
213 |
+
# parse the HTML content and extract the CSS styles
|
214 |
+
soup = BeautifulSoup(edited_text, 'html.parser')
|
215 |
+
css = ""
|
216 |
+
for style in soup.find_all('style'):
|
217 |
+
css += style.string
|
218 |
+
style.decompose()
|
219 |
+
|
220 |
+
# create a new HTML document with the CSS styles inline
|
221 |
+
new_html = f"""<html><head><style>{css}</style></head><body>{soup}</body></html>"""
|
222 |
+
|
223 |
# Save the output text as a PDF
|
224 |
+
save_as_pdf(new_html)
|
225 |
st.write("The custom obituary has been saved as a PDF.")
|
226 |
|
227 |
# Add some custom CSS to style the editor
|
|
|
243 |
</style>
|
244 |
""", unsafe_allow_html=True)
|
245 |
|
246 |
+
|
247 |
|
248 |
|
249 |
|