amoldwalunj commited on
Commit
4be8c4a
·
1 Parent(s): 81ff8be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -92,9 +92,13 @@ 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
- # Return the file name of the PDF file
96
- return pdffile.name
97
-
 
 
 
 
98
 
99
 
100
 
 
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
+ # Read the PDF file contents and encode as a base64 string
96
+ pdf_contents = pdffile.read()
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