amoldwalunj commited on
Commit
99e21c0
·
1 Parent(s): 56fcf54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -77,14 +77,14 @@ def process_text(inputs):
77
 
78
 
79
  def save_as_pdf(text):
80
- # create temporary file to save HTML
81
  with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
82
- tmpfile.write(text.encode("utf-8"))
83
  tmpfile.flush()
84
 
85
- # convert HTML to PDF using WeasyPrint
86
  pdf_file = BytesIO()
87
- HTML(filename=tmpfile.name).write_pdf(pdf_file)
88
 
89
  # encode the PDF to base64
90
  b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
 
77
 
78
 
79
  def save_as_pdf(text):
80
+ # create a temporary HTML file
81
  with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
82
+ tmpfile.write(text.encode())
83
  tmpfile.flush()
84
 
85
+ # generate a PDF from the HTML
86
  pdf_file = BytesIO()
87
+ weasyprint.HTML(tmpfile.name).write_pdf(pdf_file)
88
 
89
  # encode the PDF to base64
90
  b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')