Spaces:
Runtime error
Runtime error
Commit
·
99e21c0
1
Parent(s):
56fcf54
Update app.py
Browse files
app.py
CHANGED
@@ -77,14 +77,14 @@ def process_text(inputs):
|
|
77 |
|
78 |
|
79 |
def save_as_pdf(text):
|
80 |
-
# create temporary file
|
81 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
|
82 |
-
tmpfile.write(text.encode(
|
83 |
tmpfile.flush()
|
84 |
|
85 |
-
#
|
86 |
pdf_file = BytesIO()
|
87 |
-
HTML(
|
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')
|