amoldwalunj commited on
Commit
65a1858
·
1 Parent(s): f4e74e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -189,26 +189,31 @@ def form_page():
189
 
190
 
191
  def editor_page():
192
- #st.markdown("### Editor :smile:")
193
  st.markdown("<h1 style='text-align: center; color: Red;'>Editor</h1>", unsafe_allow_html=True)
194
-
195
  st.write("Use the editor below to edit the obituary:")
196
-
197
  quill_text = st.session_state.output_text
198
  edited_text = st_quill(quill_text)
199
-
200
  st.write("Here is the edited obituary:")
201
  #st.write(edited_text)
202
-
203
  st.session_state.edited_text = edited_text
204
-
205
  if st.button("Download as PDF"):
206
  # Save edited text as HTML string
207
- html_string = f"<html><head><style>{edited_text.get('css', '')}</style></head><body>{edited_text.get('content', '')}</body></html>"
208
  # Save HTML string as PDF file and generate download link
209
  with st.spinner("Generating PDF..."):
210
  pdf_file = save_as_pdf(html_string)
211
- st.markdown(f'<a href="{pdf_file}" download="edited_text.pdf">Download PDF</a>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
212
 
213
 
214
 
 
189
 
190
 
191
  def editor_page():
 
192
  st.markdown("<h1 style='text-align: center; color: Red;'>Editor</h1>", unsafe_allow_html=True)
 
193
  st.write("Use the editor below to edit the obituary:")
194
+
195
  quill_text = st.session_state.output_text
196
  edited_text = st_quill(quill_text)
197
+
198
  st.write("Here is the edited obituary:")
199
  #st.write(edited_text)
 
200
  st.session_state.edited_text = edited_text
201
+
202
  if st.button("Download as PDF"):
203
  # Save edited text as HTML string
204
+ html_string = f"<html><head><style>{edited_text['css']}</style></head><body>{edited_text['content']}</body></html>"
205
  # Save HTML string as PDF file and generate download link
206
  with st.spinner("Generating PDF..."):
207
  pdf_file = save_as_pdf(html_string)
208
+ with open(pdf_file, "rb") as f:
209
+ pdf_bytes = f.read()
210
+ st.download_button(
211
+ label="Download PDF",
212
+ data=pdf_bytes,
213
+ file_name="edited_text.pdf",
214
+ mime="application/pdf",
215
+ )
216
+
217
 
218
 
219