60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
from jinja2 import Environment, FileSystemLoader
|
|
import config
|
|
from process.inference import html2docx_aspose, html2pdf_pdfkit
|
|
|
|
|
|
def render_html(template, output_file_path):
|
|
# 定义报告数据
|
|
report_data = {
|
|
'report_title': '电动机起动分析报告',
|
|
'sections': [
|
|
{'title': '章节一', 'content': '内容一'},
|
|
{'title': '章节二', 'content': '内容二'}
|
|
],
|
|
'static_descriptions': [
|
|
{'name': '组件1', 'description': '这是组件1的静态描述内容。'},
|
|
{'name': '组件2', 'description': '这是组件2的静态描述内容。'}
|
|
],
|
|
'dynamic_contents': ['动态内容1', '动态内容2'],
|
|
'naming_rules': '报告的命名规则包括...',
|
|
'version_management': {
|
|
'current_version': '1.0',
|
|
'description': '初始版本',
|
|
'status': '可用'
|
|
},
|
|
'classification_attributes': '电动机态势感知类',
|
|
'table_data': [
|
|
{'col1': '数据1-1', 'col2': '数据1-2', 'col3': '数据1-3'},
|
|
{'col1': '数据2-1', 'col2': '数据2-2', 'col3': '数据2-3'}
|
|
],
|
|
'highlight_content': '这是高亮显示的内容。',
|
|
'images': [
|
|
{'src': config.image_path, 'alt': '图片1', 'caption': '这是一张示例图片1'},
|
|
{'src': config.image_path, 'alt': '图片2', 'caption': '这是一张示例图片2'}
|
|
],
|
|
'contact': {
|
|
'name': '张三',
|
|
'phone': '1234567890',
|
|
'email': 'zhangsan@example.com'
|
|
}
|
|
}
|
|
|
|
# 渲染模板
|
|
report_html = template.render(report_data)
|
|
with open(output_file_path, 'w', encoding='utf-8') as f:
|
|
f.write(report_html)
|
|
|
|
|
|
|
|
|
|
def main():
|
|
env = Environment(loader=FileSystemLoader(config.template_dir))
|
|
template = env.get_template("report_template.html")
|
|
|
|
render_html(template, config.output_html_path)
|
|
html2pdf_pdfkit(config.output_html_path, config.output_pdf_path)
|
|
html2docx_aspose(config.output_html_path, config.output_docx_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |