html转pdf去掉中间文件

parent 840e95b9
app/html/img/backimg.png

598 KB

app/html/img/logo-blue.png

17.5 KB

app/html/img/logo.png

26.9 KB

This diff is collapsed.
app/html/img/target-back.png

36 KB

app/html/img/team.png

321 KB

app/html/v2/img/cover-back.png

257 KB

app/html/v2/img/logo.png

6.92 KB

app/html/v2/img/scene.png

285 KB

app/html/v2/img/team.png

109 KB

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