本文整理汇总了Python中reportlab.platypus.paragraph.Paragraph.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Paragraph.draw方法的具体用法?Python Paragraph.draw怎么用?Python Paragraph.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus.paragraph.Paragraph
的用法示例。
在下文中一共展示了Paragraph.draw方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Figure
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import draw [as 别名]
class Figure(Flowable):
def __init__(self, imgFile, captionTxt, captionStyle, imgWidth=None, imgHeight=None, margin=(0, 0, 0, 0),
padding=(0, 0, 0, 0), align=None, borderColor=(0.75, 0.75, 0.75), no_mask=False, url=None):
imgFile = imgFile
self.imgPath = imgFile
# workaround for http://code.pediapress.com/wiki/ticket/324
# see http://two.pairlist.net/pipermail/reportlab-users/2008-October/007526.html
if no_mask:
self.i = Image(imgFile, width=imgWidth, height=imgHeight, mask=None)
else:
self.i = Image(imgFile, width=imgWidth, height=imgHeight)
self.imgWidth = imgWidth
self.imgHeight = imgHeight
self.c = Paragraph(captionTxt, style=captionStyle)
self.margin = margin # 4-tuple. margins in order: top, right, bottom, left
self.padding = padding # same as above
self.borderColor = borderColor
self.align = align
self.cs = captionStyle
self.captionTxt = captionTxt
self.availWidth = None
self.availHeight = None
self.url = url
def draw(self):
canv = self.canv
if self.align == "center":
canv.translate((self.availWidth - self.width) / 2, 0)
canv.saveState()
canv.setStrokeColor(Color(self.borderColor[0], self.borderColor[1], self.borderColor[2]))
canv.rect(self.margin[3], self.margin[2], self.boxWidth, self.boxHeight)
canv.restoreState()
canv.translate(self.margin[3] + self.padding[3], self.margin[2] + self.padding[2] - 2)
self.c.canv = canv
self.c.draw()
canv.translate((self.boxWidth - self.padding[1] - self.padding[3] - self.i.drawWidth) / 2, self.captionHeight + 2)
self.i.canv = canv
self.i.draw()
if self.url:
frags = urlparse.urlsplit(self.url.encode('utf-8'))
clean_url = urlparse.urlunsplit((frags.scheme,
frags.netloc,
urllib.quote(frags.path, safe='/'),
urllib.quote(frags.query, safe='=&'),
frags.fragment,)).decode('utf-8')
canv.linkURL(clean_url, (0, 0, self.imgWidth, self.imgHeight), relative=1, thickness=0)
def wrap(self, availWidth, availHeight):
self.availWidth = availWidth
self.availHeight = availHeight
contentWidth = max(self.i.drawWidth, self.c.wrap(self.i.drawWidth, availHeight)[0])
self.boxWidth = contentWidth + self.padding[1] + self.padding[3]
(self.captionWidth, self.captionHeight) = self.c.wrap(contentWidth, availHeight)
self.captionHeight += self.cs.spaceBefore + self.cs.spaceAfter
self.boxHeight = self.i.drawHeight + self.captionHeight + self.padding[0] + self.padding[2]
self.width = self.boxWidth + self.margin[1] + self.margin[3]
self.height = self.boxHeight + self.margin[0] + self.margin[2]
return (self.width, self.height)
示例2: beforeDrawPage
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import draw [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 draw [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)
示例4: beforeDrawPage
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import draw [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, 0.2*cm)
p.canv = canvas
p.draw()
canvas.restoreState()
if self.cover:
width = 12 * cm
img = Image.open(self.cover)
w,h = img.size
height = width/w*h
x = (page_width - width) / 2.0
y = (page_height - height) / 2.0
canvas.drawImage(self.cover, x, y, width , height)
示例5: draw
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import draw [as 别名]
def draw(self):
self.canv.saveState()
self.canv.translate(0,0)
self.canv.rotate(self.angle)
Paragraph.draw(self)
self.canv.restoreState()
示例6: draw
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import draw [as 别名]
def draw(self):
# Insert page number
'''
if 0: #for line in self.blPara.lines:
try:
for frag in line.words:
#print 111,frag.pageNumber, frag.text
if frag.pageNumber:
frag.text = str(self.canv.getPageNumber())
except Exception, e:
log.debug("PmlParagraph", exc_info=1)
'''
# Create outline
if getattr(self, "outline", False):
# Check level and add all levels
last = getattr(self.canv, "outlineLast", -1) + 1
while last < self.outlineLevel:
# print "(OUTLINE", last, self.text
key = getUID()
self.canv.bookmarkPage(key)
self.canv.addOutlineEntry(
self.text,
key,
last,
not self.outlineOpen)
last += 1
self.canv.outlineLast = self.outlineLevel
key = getUID()
# print " OUTLINE", self.outlineLevel, self.text
self.canv.bookmarkPage(key)
self.canv.addOutlineEntry(
self.text,
key,
self.outlineLevel,
not self.outlineOpen)
last += 1
#else:
# print repr(self.text)[:80]
# Draw the background and borders here before passing control on to
# ReportLab. This is because ReportLab can't handle the individual
# components of the border independently. This will also let us
# support more border styles eventually.
canvas = self.canv
style = self.style
bg = style.backColor
leftIndent = style.leftIndent
bp = style.borderPadding
x = leftIndent - bp
y = -bp
w = self.width - (leftIndent + style.rightIndent) + 2 * bp
h = self.height + 2 * bp
canvas.saveState()
if bg:
# draw a filled rectangle (with no stroke) using bg color
canvas.setFillColor(bg)
canvas.rect(x, y, w, h, fill=1, stroke=0)
def _drawBorderLine(bstyle, width, color, x1, y1, x2, y2):
# We need width and border style to be able to draw a border
if width and getBorderStyle(bstyle):
# If no color for border is given, the text color is used (like defined by W3C)
if color is None:
color = style.textColor
canvas.setStrokeColor(color)
canvas.setLineWidth(width)
canvas.line(x1, y1, x2, y2)
_drawBorderLine(style.borderTopStyle,
style.borderTopWidth,
style.borderTopColor,
x, y+h, x+w, y+h)
_drawBorderLine(style.borderBottomStyle,
style.borderBottomWidth,
style.borderBottomColor,
x, y, x+w, y)
_drawBorderLine(style.borderLeftStyle,
style.borderLeftWidth,
style.borderLeftColor,
x, y, x, y+h)
_drawBorderLine(style.borderRightStyle,
style.borderRightWidth,
style.borderRightColor,
x+w, y, x+w, y+h)
canvas.restoreState()
# we need to hide the bg color (if any) so Paragraph won't try to draw it again
style.backColor = None
# offset the origin to compensate for the padding
canvas.saveState()
canvas.translate(style.paddingLeft, -style.paddingTop)
#.........这里部分代码省略.........
示例7: draw
# 需要导入模块: from reportlab.platypus.paragraph import Paragraph [as 别名]
# 或者: from reportlab.platypus.paragraph.Paragraph import draw [as 别名]
def draw(self):
Paragraph.draw(self)
TOC.append((self._label,self.canv.getPageNumber(),self._key))
self.canv.bookmarkHorizontal('TOC_%s' % self._key,0,+20)