Spaces:
Runtime error
Runtime error
Commit
·
f4e74e3
1
Parent(s):
4be8c4a
Update app.py
Browse files
app.py
CHANGED
@@ -92,13 +92,8 @@ def save_as_pdf(html_string):
|
|
92 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as pdffile:
|
93 |
# Convert the HTML file to a PDF file using WeasyPrint
|
94 |
weasyprint.HTML(tmpfile.name).write_pdf(pdffile)
|
95 |
-
#
|
96 |
-
|
97 |
-
b64_pdf = base64.b64encode(pdf_contents).decode()
|
98 |
-
# Generate download link for the PDF file
|
99 |
-
href = f'<a href="data:application/octet-stream;base64,{b64_pdf}" download="document.pdf">Download PDF</a>'
|
100 |
-
# Display the download link using st.write
|
101 |
-
st.write(href, unsafe_allow_html=True)
|
102 |
|
103 |
|
104 |
|
@@ -207,29 +202,14 @@ def editor_page():
|
|
207 |
|
208 |
st.session_state.edited_text = edited_text
|
209 |
|
210 |
-
if st.button("
|
211 |
-
# Save
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
#toolbar {
|
219 |
-
background-color: #f3f3f3;
|
220 |
-
border-radius: 5px;
|
221 |
-
padding: 5px;
|
222 |
-
}
|
223 |
-
.ql-container {
|
224 |
-
border-radius: 5px;
|
225 |
-
border: 1px solid #ccc;
|
226 |
-
height: 400px;
|
227 |
-
}
|
228 |
-
.ql-editor {
|
229 |
-
height: 100%;
|
230 |
-
}
|
231 |
-
</style>
|
232 |
-
""", unsafe_allow_html=True)
|
233 |
|
234 |
|
235 |
|
|
|
92 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as pdffile:
|
93 |
# Convert the HTML file to a PDF file using WeasyPrint
|
94 |
weasyprint.HTML(tmpfile.name).write_pdf(pdffile)
|
95 |
+
# Return the file name of the PDF file
|
96 |
+
return pdffile.name
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
|
|
|
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 |
|
215 |
|