tfse-model-api-v0.2/Certificate/PdfCertificate.py

58 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
from reportlab.lib.units import cm, inch
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from Certificate.scripts.path_tool import *
from Report.scripts.PdfStyle import *
Width, Height = letter
class CertificateGenerator:
def __init__(self, **kwargs):
# 文字数据
self.text_data = kwargs['text_data']
# 调用模板在临时报告文件夹中创建指定名称的PDF文档
self.doc = canvas.Canvas(gen_pdf_path(name=kwargs['name']))
# 内容框
self.story = list()
def gen_cover(self):
self.doc.drawImage(get_pic_path(pic_name='certificate_02.jpg'), 0, 0, 600, 850)
def gen_text(self):
self.doc.setFont('SourceHanSerifCN-Bold', 20)
self.doc.drawString(2.9 * inch, 450, self.text_data['企业名称'])
self.doc.setFont('SIMSUN', 12, leading=5)
self.doc.drawString(2.8 * inch, 433, '统一社会信用代码:{}'.format(self.text_data['统一社会信用代码']))
self.doc.setFont('SourceHanSerifCN-Bold', 35)
self.doc.setFillColor('#B79249')
self.doc.drawString(3.2 * inch, 285, '{}级企业'.format(self.text_data['企业级别']))
self.doc.setFont('SIMSUN', 10)
self.doc.setFillColor('black')
self.doc.drawString(1.28 * inch, 260, '证书编号:{}'.format(self.text_data['证书编号']))
self.doc.setFont('SIMSUN', 10)
self.doc.drawString(4.6 * inch, 260, '有效日期:{}'.format(self.text_data['有效日期']))
def gen(self):
self.gen_cover()
self.gen_text()
self.doc.showPage()
self.doc.save()
if __name__ == '__main__':
data = {
"企业名称": "远东资信评估有限公司",
"统一社会信用代码": "91310101132508092K",
"企业级别": "AA",
"证书编号": "FECR2022010100000001",
"有效日期": "2022年1月1日至2023年1月1日",
}
file_name = '{}_{}'.format(data['企业名称'], int(time.time()))
c = CertificateGenerator(name=file_name, text_data=data)
c.gen()