Update utils.py
Browse files
utils.py
CHANGED
|
@@ -96,10 +96,16 @@ def gen_html(num):
|
|
| 96 |
return all_q
|
| 97 |
|
| 98 |
def convert_html_to_pdf(source_html, output_filename):
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
return pisa_status.err
|
|
|
|
| 96 |
return all_q
|
| 97 |
|
| 98 |
def convert_html_to_pdf(source_html, output_filename):
|
| 99 |
+
try:
|
| 100 |
+
result_file = open(output_filename, "w+b")
|
| 101 |
+
pisa_status = pisa.CreatePDF(
|
| 102 |
+
io.StringIO(source_html),
|
| 103 |
+
dest=result_file
|
| 104 |
+
)
|
| 105 |
+
result_file.close()
|
| 106 |
+
if pisa_status.err:
|
| 107 |
+
raise Exception("Error converting HTML to PDF")
|
| 108 |
+
except Exception as e:
|
| 109 |
+
print(f"Error: {e}")
|
| 110 |
+
raise
|
| 111 |
return pisa_status.err
|