我正在尝试使用reportlab。我知道如何添加字符串,行等。现在我希望能够将静态文本与段落相结合,并且静态文本需要处于特定位置。对不起,缩进错误。
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.platypus import Image, SimpleDocTemplate, Paragraph, Spacer,
from reportlab.rl_config import defaultPageSize
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_JUSTIFY
PAGE_HEIGHT=defaultPageSize[1]; PAGE_WIDTH=defaultPageSize[0]
Story = []
p = "This is a paragraph"
last_name = "John"
first_name = "Doe"
dosuren = "02-03-2016"
def generate_report(last_name, first_name, dosuren):
pdf_file_name = last_name + first_name + "_" + dosuren + ".pdf"
c= canvas.Canvas(pdf_file_name, pagesize=letter)
c.setFont('Times-Bold', 12,leading=None )
c.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, "REPORT")
##### Static Text ############
c.setFont('Times-Bold', 12, leading=None)
c.drawString(30, 320, "Subject INfo:")
c.setFont('Times-Roman', 12, leading=None)
c.drawString(30, 380, "Subject info2:")
##Paragraph###
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
Story.append(Paragraph(p, styles["Justify"]))
c.showPage()
c.save()
答案 0 :(得分:0)
根据您的要求,很明显您正在寻找>=
,它允许您首先在页面上绘制一些固定元素,然后添加PageTemplate
&#39}和其他{{1对它来说。
一个简单的例子如下:
Paragraph