本文整理汇总了Python中reportlab.platypus.paragraph.Paragraph.canv方法的典型用法代码示例。如果您正苦于以下问题:Python Paragraph.canv方法的具体用法?Python Paragraph.canv怎么用?Python Paragraph.canv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus.paragraph.Paragraph
的用法示例。
在下文中一共展示了Paragraph.canv方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: beforeDrawPage
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import canv [as 别名]
def beforeDrawPage(self,canvas,doc):
canvas.setFont(serif_font,10)
canvas.setLineWidth(0)
#header
canvas.line(header_margin_hor, page_height - header_margin_vert, page_width - header_margin_hor, page_height - header_margin_vert )
if pdfstyles.show_page_header:
canvas.saveState()
canvas.resetTransforms()
canvas.translate(header_margin_hor, page_height - header_margin_vert - 0.1*cm)
p = Paragraph(self.title, text_style())
p.canv = canvas
p.wrap(page_width - header_margin_hor*2.5, page_height) # add an extra 0.5 margin to have enough space for page number
p.drawPara()
canvas.restoreState()
canvas.drawRightString(page_width - header_margin_hor, page_height - header_margin_vert + 0.1 * cm, "%d" % doc.page)
#Footer
canvas.saveState()
canvas.setFont(serif_font,8)
canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert )
if pdfstyles.show_page_footer:
p = Paragraph(formatter.cleanText(pagefooter, escape=False), text_style())
p.canv = canvas
w,h = p.wrap(page_width - header_margin_hor*2.5, page_height)
p.drawOn(canvas, footer_margin_hor, footer_margin_vert - 10 - h)
canvas.restoreState()
示例2: beforeDrawPage
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import canv [as 别名]
def beforeDrawPage(self, canvas, doc):
canvas.setFont(serif_font, 8)
canvas.saveState()
if pdfstyles.show_title_page_footer:
canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert)
footertext = [_(titlepagefooter)]
if pdfstyles.show_creation_date:
locale.setlocale(locale.LC_ALL, "")
footertext.append(
pdfstyles.creation_date_txt % time.strftime(pdfstyles.creation_date_format, time.localtime())
)
lines = [formatter.cleanText(line, escape=False) for line in footertext]
txt = "<br/>".join(line if isinstance(line, unicode) else unicode(line, "utf-8") for line in lines)
p = Paragraph(txt, text_style(mode="footer"))
w, h = p.wrap(print_width, print_height)
canvas.translate((page_width - w) / 2.0, footer_margin_vert - h - 0.25 * cm)
p.canv = canvas
p.draw()
canvas.restoreState()
if self.cover:
width, height = self._scale_img(pdfstyles.title_page_image_size, self.cover)
if pdfstyles.title_page_image_pos[0] is None:
x = (page_width - width) / 2.0
else:
x = max(0, min(page_width - width, pdfstyles.title_page_image_pos[0]))
if pdfstyles.title_page_image_pos[1] is None:
y = (page_height - height) / 2.0
else:
y = max(0, min(page_height - height, pdfstyles.title_page_image_pos[1]))
canvas.drawImage(self.cover, x, y, width, height)
示例3: beforeDrawPage
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import canv [as 别名]
def beforeDrawPage(self,canvas,doc):
canvas.setFont(serif_font,8)
canvas.saveState()
if pdfstyles.show_title_page_footer:
canvas.line(footer_margin_hor, footer_margin_vert, page_width - footer_margin_hor, footer_margin_vert )
footertext = [_(titlepagefooter)]
if pdfstyles.show_creation_date:
footertext.append('PDF generated at: %s' % strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()))
p = Paragraph('<br/>'.join([formatter.cleanText(line, escape=False) for line in footertext]),
text_style(mode='footer'))
w,h = p.wrap(print_width, print_height)
canvas.translate( (page_width-w)/2.0, footer_margin_vert - h - 0.25*cm)
p.canv = canvas
p.draw()
canvas.restoreState()
if self.cover:
width, height = self._scale_img(pdfstyles.title_page_image_size, self.cover)
if pdfstyles.title_page_image_pos[0] == None:
x = (page_width - width) / 2.0
else:
x = max(0, min(page_width-width, pdfstyles.title_page_image_pos[0]))
if pdfstyles.title_page_image_pos[1] == None:
y = (page_height - height) / 2.0
else:
y = max(0, min(page_height-height, pdfstyles.title_page_image_pos[1]))
canvas.drawImage(self.cover, x, y, width , height)