64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
import time
|
||
|
||
from reportlab.lib.colors import HexColor
|
||
from reportlab.lib.units import cm, inch
|
||
from reportlab.platypus import Paragraph, Image, PageBreak, Frame, Table
|
||
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
|
||
from reportlab.platypus.tableofcontents import TableOfContents
|
||
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.jpg'), 0, 0, 600, 850)
|
||
|
||
def gen_text(self):
|
||
style = getSampleStyleSheet()
|
||
|
||
self.doc.setFont('SourceHanSans-ExtraLight', 20)
|
||
self.doc.drawString(2.9 * inch, 450, self.text_data['企业名称'])
|
||
self.doc.setFont('SourceHanSans-ExtraLight', 12, leading=5)
|
||
self.doc.drawString(2.8 * inch, 433, '统一社会信用代码:{}'.format(self.text_data['统一社会信用代码']))
|
||
self.doc.setFont('SourceHanSans-ExtraLight', 35)
|
||
self.doc.setFillColor('#B79249')
|
||
self.doc.drawString(3.2 * inch, 285, self.text_data['企业级别'])
|
||
self.doc.setFont('SourceHanSans-ExtraLight', 10)
|
||
self.doc.setFillColor('black')
|
||
self.doc.drawString(1.28 * inch, 260, '证书编号:{}'.format(self.text_data['证书编号']))
|
||
self.doc.setFont('SourceHanSans-ExtraLight', 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()
|
||
|