ymcmy commited on
Commit
6f71715
·
verified ·
1 Parent(s): 88254ad

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +11 -0
utils.py CHANGED
@@ -2,6 +2,8 @@ from bs4 import BeautifulSoup
2
  import requests
3
  import numpy as np
4
  from datetime import datetime
 
 
5
 
6
  def gen_link():
7
  if np.random.choice([True, False]):
@@ -92,3 +94,12 @@ def gen_html(num):
92
  </html>
93
  '''
94
  return all_q
 
 
 
 
 
 
 
 
 
 
2
  import requests
3
  import numpy as np
4
  from datetime import datetime
5
+ from xhtml2pdf import pisa
6
+ import io
7
 
8
  def gen_link():
9
  if np.random.choice([True, False]):
 
94
  </html>
95
  '''
96
  return all_q
97
+
98
+ def convert_html_to_pdf(source_html, output_filename):
99
+ result_file = open(output_filename, "w+b")
100
+ pisa_status = pisa.CreatePDF(
101
+ io.StringIO(source_html),
102
+ dest=result_file
103
+ )
104
+ result_file.close()
105
+ return pisa_status.err