amoldwalunj commited on
Commit
bb6b6cc
·
1 Parent(s): c9e15ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -57,22 +57,21 @@ def process_text(inputs):
57
 
58
  import base64
59
  from io import BytesIO
60
- from delta import Delta, Renderer
61
-
62
  from weasyprint import HTML
63
 
64
  def save_as_pdf(text):
65
- # convert quill editor Delta object to HTML and render with Renderer
66
  delta = Delta(text)
67
- html = Renderer().render(delta)
68
-
69
  # convert HTML to PDF
70
  pdf_file = BytesIO()
71
- HTML(string=html).write_pdf(pdf_file)
72
-
73
  # encode the PDF to base64
74
  b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
75
-
76
  # generate a download link for the PDF
77
  href = f'<a href="data:application/octet-stream;base64,{b64}" download="output.pdf">Download PDF</a>'
78
  st.markdown(href, unsafe_allow_html=True)
 
57
 
58
  import base64
59
  from io import BytesIO
60
+ from delta import Delta, html
 
61
  from weasyprint import HTML
62
 
63
  def save_as_pdf(text):
64
+ # convert quill editor Delta object to HTML
65
  delta = Delta(text)
66
+ html_str = html.render(delta)
67
+
68
  # convert HTML to PDF
69
  pdf_file = BytesIO()
70
+ HTML(string=html_str).write_pdf(pdf_file)
71
+
72
  # encode the PDF to base64
73
  b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
74
+
75
  # generate a download link for the PDF
76
  href = f'<a href="data:application/octet-stream;base64,{b64}" download="output.pdf">Download PDF</a>'
77
  st.markdown(href, unsafe_allow_html=True)