from reportlab.platypus import SimpleDocTemplate, Image, Paragraph
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.pdfgen import canvas
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase import pdfmetrics
pdfmetrics.registerFont(TTFont('SimKai', 'D:\\Anaconda3\\envs\\torch1.5\\Lib\\site-packages\\reportlab\\fonts\\SimKai.ttf'))
doc = SimpleDocTemplate("Hello1.pdf")
styles = getSampleStyleSheet()
style0 = styles["Title"]
style0.fontName = "SimKai"
style = styles['Normal']
style.fontName = "SimKai"
style1 = styles["Heading3"]
style1.fontName = "SimKai"
style1.alignment = 1
story =[]
story.append(Paragraph("XX Eye chart diagnosis report of University Hospital ", style0))
story.append(Paragraph(" full name :XXX", style))
story.append(Paragraph(" Age :23", style))
story.append(Paragraph(" Gender : male ", style))
story.append(Paragraph("XX Diagnostic diagram :", style))
t = Image("E:\\1.png", width=300, height=200) ## Image path address
story.append(t)
story.append(Paragraph(" result : Everything is all right ", style))
story.append(Paragraph(" date :2022 year 6 month 15 Japan ", style))
story.append(Paragraph("XX University Hospital ", style1))
doc.build(story)
About ParagraphStyle The parameters of are as follows :
We select several important parameters to explain :
Description of formal parameters of fonts :
Here is what the system provides Normal Format , Actually Normal Format and ParagraphStyle It's exactly the same , except Normal Format , Other formats are also available .
Reference:
use Python Quickly and automatically generate pictures and texts PDF file - You know (zhihu.com)https://zhuanlan.zhihu.com/p/318390273