html转pdf去掉中间文件

parent 840e95b9
This diff is collapsed.
......@@ -243,7 +243,6 @@ class DataIntegrate:
# template = env.get_template('monthReport.html') # 获取一个模板文件
template = env.get_template('/v2/monthReportV2.html') # 获取一个模板文件
monthReport_html = template.render(data) # 渲染
# 保存 monthReport_html
# save_file = "app/html/monthReport.html"
# with open(save_file, 'w', encoding="utf-8") as f:
......
......@@ -6,7 +6,10 @@
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import base64
import os
import time
from io import BytesIO
import imgkit
......@@ -15,6 +18,7 @@ from pyecharts.charts import Radar, Bar
import uuid
import cv2
from app.api.engine import work_dir
import numpy as np
def gen_radar_chart(radar_chart_data):
......@@ -24,7 +28,6 @@ def gen_radar_chart(radar_chart_data):
目前无法实现的功能:
1、雷达图周围的图例的 textStyle 暂时无法设置背景颜色
"""
# v1 = [[4300, 10000, 28000, 35000, 50000]]
radar_chart = radar_chart_data['data'][0:5]
v1 = [[data['data'] for data in radar_chart]]
radar = Radar(
......@@ -70,21 +73,22 @@ def gen_radar_chart(radar_chart_data):
}),
legend_opts=opts.LegendOpts(selected_mode=False, is_show=False)
)
html_name = work_dir + '/app/html/' + str(uuid.uuid4()) + '.html'
img_name = work_dir + '/app/html/img/radar_chart_' + str(uuid.uuid4()) + '.png'
radar.render(html_name)
imgkit.from_file(html_name, img_name)
html = radar.render_embed()
start = time.time()
image_bin = imgkit.from_string(html, None)
print('propose_fund cost', time.time() - start)
# 读取图片
img = cv2.imread(img_name)
img1 = np.frombuffer(image_bin, np.uint8)
img = cv2.imdecode(img1, cv2.IMREAD_ANYCOLOR)
# 获取宽度和高度
height = len(img)
width = len(img[0])
img = img[0:height, 160:750]
cv2.imwrite(img_name, img)
os.popen('rm -f {}'.format(html_name))
return img_name
img_bin = cv2.imencode(".png", img)[1].tobytes()
img_content = 'data:image/png;base64,' + base64.b64encode(img_bin).decode('utf-8')
return img_content
if __name__ == '__main__':
gen_radar_chart()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment