本文整理汇总了Python中reportlab.platypus.Paragraph类的典型用法代码示例。如果您正苦于以下问题:Python Paragraph类的具体用法?Python Paragraph怎么用?Python Paragraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paragraph类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: footer_building
def footer_building(canvas, doc, styles):
pageinfo = _('scores_sheet')
footer = Paragraph(''' <para align=right>Page %d - %s </para>''' % (doc.page, pageinfo), styles['Normal'])
w, h = footer.wrap(doc.width, doc.bottomMargin)
footer.drawOn(canvas, doc.leftMargin, h)
#
#
#
#
# class NumberedCanvas(canvas.Canvas):
# def __init__(self, *args, **kwargs):
# canvas.Canvas.__init__(self, *args, **kwargs)
# self._saved_page_states = []
#
# def showPage(self):
# self._saved_page_states.append(dict(self.__dict__))
# self._startPage()
#
# def save(self):
# """add page info to each page (page x of y)"""
# num_pages = len(self._saved_page_states)
# for state in self._saved_page_states:
# self.__dict__.update(state)
# self.draw_page_number(num_pages)
# canvas.Canvas.showPage(self)
# canvas.Canvas.save(self)
#
# def draw_page_number(self, page_count):
# self.setFont("Helvetica", 7)
# self.drawRightString(200*mm, 20*mm,
# "Page %d of %d" % (self._pageNumber, page_count))
开发者ID:verpoorten,项目名称:immobilier,代码行数:32,代码来源:merge_pdf.py
示例2: draw
def draw(self):
canvas = self.canv
h, w = float(self.img.height), float(self.img.width)
if not self.img.iptc.caption:
fsz = 5.0
else:
fsz = 0.85*inch
if w > h*1.3:
fsz = 0.25*inch
s = self.size - fsz
if h > w:
ratio = w / h
h = s
w = s * ratio
else:
ratio = h / w
w = s
h = s * ratio
img = Image(self.img.path, height=h, width=w)
w, h = img.wrap(w, h)
iw, ih = w, h
imgx, imgy = (self.size - s - (fsz/2.0), self.size - h)
img.drawOn(self.canv, imgx, imgy)
print "%.2f x %.2f (%.2f x %.2f dpi)" % (w/inch, h/inch, float(o.width) / (w/inch), float(o.height) / (h/inch) )
p = Paragraph(self.img.iptc.caption, styleN)
w, h = p.wrap(self.size - 10.0, 1.3*inch)
print "Text %.2f x %.2f" % (w/inch, h/inch)
p.drawOn(self.canv, 3.0, (imgy - h) - 3.0)
canvas.rect(imgx, imgy, iw, ih, stroke=1, fill=0)
开发者ID:robmyers,项目名称:codebag,代码行数:29,代码来源:imagepdf.py
示例3: fit_text
def fit_text(c, text, x, y, max_w, max_h, font_name='Helvetica',
padding_w=4.5, padding_h=4.5, font_decrement=0.0625):
"""Draw text, reducing font size until it fits with a given max width and
height."""
max_w -= (padding_w * 2.0)
max_h -= (padding_h * 2.0)
x += padding_w
y += padding_h
font_size = max_h
while font_size > 1.0:
ps = ParagraphStyle(name='text', alignment=TA_CENTER,
fontName=font_name, fontSize=font_size,
leading=font_size)
p = Paragraph(text, ps)
actual_w, actual_h = p.wrapOn(c, max_w, max_h)
if actual_h > max_h or actual_w > max_w:
font_size -= font_decrement
else:
y_pad = (max_h - actual_h) / 2
p.drawOn(c, x, y + y_pad)
return
开发者ID:alfredo,项目名称:django-badger,代码行数:25,代码来源:printing.py
示例4: _draw_textarea
def _draw_textarea(self, canvas: Canvas, op: OrderPosition, order: Order, o: dict):
font = o['fontfamily']
if o['bold']:
font += ' B'
if o['italic']:
font += ' I'
align_map = {
'left': TA_LEFT,
'center': TA_CENTER,
'right': TA_RIGHT
}
style = ParagraphStyle(
name=uuid.uuid4().hex,
fontName=font,
fontSize=float(o['fontsize']),
leading=float(o['fontsize']),
autoLeading="max",
textColor=Color(o['color'][0] / 255, o['color'][1] / 255, o['color'][2] / 255),
alignment=align_map[o['align']]
)
text = re.sub(
"<br[^>]*>", "<br/>",
bleach.clean(
self._get_text_content(op, order, o) or "",
tags=["br"], attributes={}, styles=[], strip=True
)
)
p = Paragraph(text, style=style)
p.wrapOn(canvas, float(o['width']) * mm, 1000 * mm)
# p_size = p.wrap(float(o['width']) * mm, 1000 * mm)
ad = getAscentDescent(font, float(o['fontsize']))
p.drawOn(canvas, float(o['left']) * mm, float(o['bottom']) * mm - ad[1])
开发者ID:FlaviaBastos,项目名称:pretix,代码行数:33,代码来源:pdf.py
示例5: drawText
def drawText(self,txt,x,y,w,h,style={}):
margin = 0
self.canvas.saveState()
path = self.canvas.beginPath()
path.rect(x,y,w,h)
self.canvas.clipPath(path,stroke=1)
_s = styles['BodyText']
_s = ParagraphStyle({})
_s.fontSize = style['fontSize']*1.0
# _s.fontSize = style['fontSize']
_s.leading = style['fontSize']
print _s
print 'writing text',txt,x,y
while _s.fontSize > 1.0:
p = Paragraph(txt.strip(),_s)
aw,ah = p.wrapOn(self.canvas,w-margin*2,h-margin*2)
print aw,w-margin*2,ah,h-margin*2,_s.fontSize
break
if (aw > w-margin*2) or (ah > h-margin*2):
_s.fontSize = _s.fontSize - 1
_s.leading = _s.fontSize*1.9
else:
break
p.drawOn(self.canvas,x+margin,y+margin)
self.canvas.restoreState()
开发者ID:shivanan,项目名称:labelmaker,代码行数:25,代码来源:makelabels.py
示例6: createParagraph
def createParagraph(c, text, x, y):
""""""
style = getSampleStyleSheet()
width, height = letter
p = Paragraph(text, style=style["Normal"])
p.wrapOn(c, width, height)
p.drawOn(c, x, y, mm)
开发者ID:kkiley,项目名称:RoastMaster,代码行数:7,代码来源:showFonts2.py
示例7: adicionais
def adicionais(self, oXML=None):
el_infAdic = oXML.find(
".//{http://www.portalfiscal.inf.br/nfe}infAdic")
self.nlin += 2
self.canvas.setFont('NimbusSanL-Bold', 6)
self.string(self.nLeft + 1, self.nlin + 1, 'DADOS ADICIONAIS')
self.canvas.setFont('NimbusSanL-Regu', 5)
self.string(self.nLeft + 1, self.nlin + 4,
'INFORMAÇÕES COMPLEMENTARES')
self.string(
((self.width / 3)*2) + 1, self.nlin + 4, 'RESERVADO AO FISCO')
self.rect(self.nLeft, self.nlin + 2,
self.width - self.nLeft - self.nRight, 42)
self.vline((self.width / 3)*2, self.nlin + 2, 42)
# Conteúdo campos
styles = getSampleStyleSheet()
styleN = styles['Normal']
styleN.fontSize = 6
styleN.fontName = 'NimbusSanL-Regu'
styleN.leading = 7
fisco = tagtext(oNode=el_infAdic, cTag='infAdFisco')
observacoes = tagtext(oNode=el_infAdic, cTag='infCpl')
if fisco:
observacoes = fisco + ' ' + observacoes
P = Paragraph(observacoes, styles['Normal'])
w, h = P.wrap(128 * mm, 32 * mm)
altura = (self.height - self.nlin - 5) * mm
P.drawOn(self.canvas, (self.nLeft + 1) * mm, altura - h)
self.nlin += 36
开发者ID:danimaribeiro,项目名称:PyTrustNFe,代码行数:30,代码来源:danfe.py
示例8: draw
def draw(self):
self.canv.saveState()
self.canv.rotate(self.rotation)
self.canv.translate(-self.width / 2. - 100, -self.height)
Paragraph.draw(self)
self.canv.restoreState()
开发者ID:NMGRL,项目名称:pychron,代码行数:7,代码来源:irradiation_pdf_writer.py
示例9: add_to_toc_and_return
def add_to_toc_and_return(self, text, sty):
data = str(text + sty.name).encode()
bn = sha1(data).hexdigest()
h = Paragraph(text + '<a name="%s"/>' % bn, sty)
# store the bookmark name on the flowable so afterFlowable can see this
h._bookmarkName = bn
return h
开发者ID:oledm,项目名称:gmp,代码行数:7,代码来源:helpers.py
示例10: addParaWithThumb
def addParaWithThumb(self, text, pageY, style, thumbSrc=None):
""" Adds paragraph text to point on PDF info page """
c = self.figureCanvas
aW = self.pageWidth - (inch * 2)
maxH = self.pageHeight - inch
spacer = 10
imgw = imgh = 25
# Some html from markdown may not be compatible
# with adding to PDF.
try:
para = Paragraph(text, style)
except ValueError:
print "Couldn't add paragraph to PDF:"
print text
text = "[Failed to format paragraph - not shown]"
para = Paragraph(text, style)
w, h = para.wrap(aW, pageY) # find required space
if thumbSrc is not None:
parah = max(h, imgh)
else:
parah = h
# If there's not enough space, start a new page
if parah > (pageY - inch):
print "new page"
c.save()
pageY = maxH # reset to top of new page
indent = inch
if thumbSrc is not None:
c.drawImage(thumbSrc, inch, pageY - imgh, imgw, imgh)
indent = indent + imgw + spacer
para.drawOn(c, indent, pageY - h)
return pageY - parah - spacer # reduce the available height
开发者ID:romainGuiet,项目名称:figure,代码行数:33,代码来源:Figure_To_Pdf.py
示例11: do_attendee
def do_attendee (attendee, annotation, c, x, y, framesize):
link = attendee.value
cn = attendee.params.get("CN")
nameaddr = cn and cn[0]
if nameaddr:
realname, emailaddr = parseaddr(nameaddr.replace(",", "%2C"))
if realname:
text = realname.replace("%2C", ",")
elif emailaddr:
text = emailaddr
else:
text = nameaddr
elif link:
text = link
text = htmlescape(text)
if link:
text = '<link href="' + link + '">' + text + '</link>'
if annotation:
text += ' <i>' + annotation + '</i>'
p = Paragraph(text, ParagraphStyle("normal"))
w, h = p.wrapOn(c, *framesize)
y -= h
p.drawOn(c, x, y)
# y -= (0.1 * inch)
return y
开发者ID:project-renard-survey,项目名称:xerox-parc-uplib-mirror,代码行数:25,代码来源:parser.py
示例12: create_header
def create_header(self):
headerCanvas = Drawing()
headerRect = Rect(0, 0, width=self.width, height=50)
headerRect.fillColor = HexColor("#607D8B")
headerRect.strokeColor = HexColor("#607D8B")
headerCanvas.add(headerRect)
renderPDF.draw(headerCanvas, self.c, 0, self.height - 50)
_header_styles = ParagraphStyle(
"Header",
parent=self.styles["Heading1"],
textColor=white,
fontName='Helvetica'
)
p = Paragraph("Kit Trading Fund Report", style = _header_styles)
p.wrapOn(self.c, self.width, self.height - 50)
p.drawOn(self.c, *self.coord(75, 10, mm))
_sub_header_styles = ParagraphStyle(
"SubHeader",
parent=self.styles["Heading4"],
textColor=white,
fontName='Helvetica'
)
p = Paragraph("Monthly Report: January 2016", style = _sub_header_styles)
p.wrapOn(self.c, self.width, self.height - 50)
p.drawOn(self.c, *self.coord(85, 16, mm))
开发者ID:denisvolokh,项目名称:reportlab-report-prototype,代码行数:28,代码来源:main2.py
示例13: addTable
def addTable(self,ndata,nkeys=None):
data = []
if not nkeys:
keys = self.hlib.getKeys(ndata)
data.append(keys)
else:
keys = nkeys
data.append(nkeys)
for x in ndata:
lister = []
for b in range(len(keys)):
if keys[b] not in x:
outb = None
else:
outb = x[keys[b]]
t = Paragraph(str(outb),self.styles["Normal"])
lister.append(t)
data.append(lister)
tblStyle = TableStyle([('TEXTCOLOR',(0,0),(-1,-1),black),
('VALIGN',(0,0),(-1,-1),'TOP'),
('BOX',(0,0),(-1,-1),1,black),
('INNERGRID',(0,0),(-1,-1),1,black),
('BACKGROUND',(0,0),(-1,0),lightblue)])
t = LongTable(data,repeatRows=1)
t.setStyle(tblStyle)
self.story.append(t)
self.story.append(CondPageBreak(6))
开发者ID:ddfelts,项目名称:hawk2.0,代码行数:29,代码来源:hawkPDF.py
示例14: footer
def footer(canvas, doc):
canvas.saveState()
P = Paragraph("ReadyMade Report",
styleN)
w, h = P.wrap(doc.width, doc.bottomMargin)
P.drawOn(canvas, doc.leftMargin, h)
canvas.restoreState()
开发者ID:priya-I,项目名称:ReadyMade,代码行数:7,代码来源:test.py
示例15: processPDFLine
def processPDFLine(canvas, type, text, lineno, page, font, width, height):
text = re.sub("("+CHAR_BOLDITALUNDER+")([^/]+)(/"+CHAR_BOLDITALUNDER+")", r"<font name=CourierPrimeBI size=12><u>\2</u></font>", text)
text = re.sub("("+CHAR_BOLDITAL+")([^/]+)(/"+CHAR_BOLDITAL+")", r"<font name=CourierPrimeBI size=12>\2</font>", text)
text = re.sub("("+CHAR_BOLDUNDER+")([^/]+)(/"+CHAR_BOLDUNDER+")", r"<font name=CourierPrimeB size=12><u>\2</u></font>", text)
text = re.sub("("+CHAR_ITALUNDER+")([^/]+)(/"+CHAR_ITALUNDER+")", r"<font name=CourierPrimeI size=12><u>\2</u></font>", text)
text = re.sub("("+CHAR_BOLD+")([^/]+)(/"+CHAR_BOLD+")", r"<font name=CourierPrimeB size=12>\2</font>", text)
text = re.sub("("+CHAR_ITAL+")([^/]+)(/"+CHAR_ITAL+")", r"<font name=CourierPrimeI size=12>\2</font>", text)
text = re.sub("("+CHAR_UNDER+")([^/]+)(/"+CHAR_UNDER+")", r"<u>\2</u>", text)
text = re.sub("("+CHAR_COMMENT+")([^/]+)(/"+CHAR_COMMENT+")", r"</para><para bg=#FAFAD2><u>\2</u></para><para>", text)
elm = fparser.fromTypeTextToElm(type, text)
marginLeft = leftMarginForElement(elm, page)
marginRight = rightMarginForElement(elm, page)
# Styling Additions
if elm.elmType == "Scene Heading":
text = "<font name=CourierPrimeB size=12>" + text + "</font>"
if elm.elmType == "Lyrics":
text = "<font name=CourierPrimeI size=12>" + text + "</font>"
if elm.elmType == "Comment":
text = "</para><para bg=#FAFAD2><u>" + text + "</u></para><para>"
if elm.elmType == "Transition": # right align
para = Paragraph(text, pstyleRight)
para.wrapOn(canvas, width, pstyleRight.fontSize*font.heightEM)
para.drawOn(canvas,-marginRight*inch, height - (lineno+1)*pstyle.fontSize*font.heightEM - page.marginTop*inch)
else:
para = Paragraph(text, pstyle)
para.wrapOn(canvas, width, pstyle.fontSize*font.heightEM)
para.drawOn(canvas, marginLeft*inch, height - (lineno+1)*pstyle.fontSize*font.heightEM - page.marginTop*inch)
开发者ID:jeffreysanti,项目名称:fountainTools,代码行数:32,代码来源:pdfOut.py
示例16: Page_Setup
def Page_Setup(canvas, doc):
canvas.saveState()
canvas.setFillColor(doc.gs_background)
canvas.rect(0,0,8.5*inch, 11*inch,fill=1)
if canvas.getPageNumber() == 1:
canvas.drawImage(doc.leftLogoFile,x=0.3*inch, y=8.7*inch,\
width=0.92*inch, mask='auto', preserveAspectRatio=True)
canvas.drawImage(doc.rightLogoFile,x=7.3*inch, y=8.7*inch,\
width=0.92*inch, mask='auto', preserveAspectRatio=True)
Normal_Style=ParagraphStyle('normal')
Footer_Style = ParagraphStyle('my-footer-style', parent=Normal_Style,
textColor=colors.white, backColor=colors.black, alignment=TA_CENTER,
fontSize=6, leading=7,fontName='Courier',borderPadding=(0,0,5,0))
P = Paragraph("The New Hampshire Liberty Alliance is a non-partisan coalition "
"working to increase individual liberty, and encourage citizen "
"involvement in the legislative process. Bills on the Gold Standard "
"are evaluated based on their effects on, among other things; civil "
"liberties, personal responsibility, property rights, "
"accountability, constitutionality, and taxation. Roll call votes on "
"Gold Standard bills are the foundation for our annual Liberty "
"Rating report card.", Footer_Style)
w,h = P.wrap(doc.width, doc.bottomMargin)
P.drawOn(canvas, doc.leftMargin,3)
canvas.restoreState()
开发者ID:jcreem,项目名称:bill-tools,代码行数:32,代码来源:utils.py
示例17: render
def render(self):
style = getSampleStyleSheet()['Normal']
style.alignment = self.text_align
style.fontName = self.font_name
if self._layout.debug_fields:
style.backColor = "rgba(255, 0, 0, 0.5)"
if self.fit_text:
original_size = self.font_size
text_width = stringWidth(self.data, self.font_name, self.font_size)
while text_width > self.width:
self.font_size -= 1
text_width = stringWidth(self.data, self.font_name, self.font_size)
# Size has been adjusted. Lower text accordingly
if original_size > self.font_size:
self._offset_top = (original_size - self.font_size) / 2.0
if self.height == 0:
self.height = self.font_size
style.fontSize = self.font_size
style.leading = self.font_size
p = Paragraph('<font color="%s">%s</font>' % (self.color, self.data), style)
p.wrap(self.width, self.height)
top = self._layout.height - self.top - self.height - self._offset_top
p.drawOn(self._canvas, self.left, top)
开发者ID:suda,项目名称:stereo,代码行数:27,代码来源:text.py
示例18: create_para
def create_para(self, xmltext, current_w, current_h, offset_font_size=0):
para_text = extract_text(xmltext)
font_name = xmltext.get('font_family')
if font_name is None:
font_name = 'sans-serif'
align = xmltext.get('text_align')
if para_text.startswith('<center>'):
align = 'center'
if (align == 'left') or (align == 'start'):
alignment = TA_LEFT
elif align == 'center':
alignment = TA_CENTER
else:
alignment = TA_RIGHT
if xmltext.get('font_size') is None:
font_size = 10.0 - offset_font_size
else:
font_size = float(xmltext.get('font_size')) - offset_font_size
if xmltext.get('line_height') is None:
line_height = 11
else:
line_height = int(xmltext.get('line_height'))
style = ParagraphStyle(name='text', fontName=font_name, fontSize=font_size,
alignment=alignment, leading=line_height)
# six.print_("%s:%s" % (xmltext.tag, para_text))
text = Paragraph(para_text, style=style)
_, new_current_h = text.wrapOn(self.pdf, current_w, current_h)
return text, style, new_current_h
开发者ID:Lucterios2,项目名称:core,代码行数:28,代码来源:reporting.py
示例19: GetParagraphes
def GetParagraphes(self, texte="", taille_police=None):
style = ParagraphStyle(name="style", fontName=self.parent.dictDonnees["case_nom_police"], fontSize=taille_police,
spaceBefore=0, spaceafter=0, leftIndent=0, rightIndent=0, alignment=1, leading=taille_police,
textColor=ColorWxToPdf(self.parent.dictDonnees["case_texte_couleur"]))
liste_paragraphes = []
hauteur_paragraphes = 0
for texte_paragraphe in texte.split("\n") :
# Remplacement des légendes
liste_legendes = REGEX_LEGENDES.findall(texte_paragraphe)
for chaine in liste_legendes :
IDlegende = int(chaine[1:-1])
if self.parent.dictDonnees["legendes"].has_key(IDlegende) and self.parent.dictNumerosLegendes.has_key(IDlegende):
couleur = UTILS_Images.rgb_to_hex(self.parent.dictDonnees["legendes"][IDlegende]["couleur"])
if self.parent.dictDonnees["legende_type"] == "numero":
numero = self.parent.dictNumerosLegendes[IDlegende]
chaine_remplacement = u"<font color='%s' size='-2'><super>%d</super></font>" % (couleur, numero)
elif self.parent.dictDonnees["legende_type"] == "carre":
chaine_remplacement = u"<font face='ZapfDingbats' color='%s' size='-2'><super>X</super></font>" % couleur
else :
chaine_remplacement = ""
else :
chaine_remplacement = u""
texte_paragraphe = texte_paragraphe.replace(chaine, chaine_remplacement)
# Création du paragraphe
paragraphe = Paragraph(texte_paragraphe, style=style)
largeur_paragraphe, hauteur_paragraphe = paragraphe.wrapOn(self.canvas, self.largeur_case, self.hauteur_case)
hauteur_paragraphes += hauteur_paragraphe
liste_paragraphes.append((hauteur_paragraphe, paragraphe))
return liste_paragraphes, hauteur_paragraphes
开发者ID:bogucool,项目名称:Noethys,代码行数:33,代码来源:UTILS_Impression_menu.py
示例20: generate_pdf
def generate_pdf(story, existing_canvas=None):
styleSheet = getSampleStyleSheet()
style = styleSheet['BodyText']
c = existing_canvas or canvas.Canvas(OUT_FILENAME, pagesize=A5)
#c.setFont("Helvetica", 28)
# draw some lines
#a5 is 210 mm * 148 mm
c.rect(1*cm, 1*cm, 12.8*cm, 19*cm, fill=0)
c.rotate(90)
style.fontSize = 24
style.leading = 24
story_points = "%s points" % story['Story points'] if story['Story points'] else 'Not estimated'
title = Paragraph("%s [%s]" % (story['Subject'],story_points), style)
title.wrap(17*cm, 4*cm)
title.drawOn(c, 2*cm, -3.5*cm)
# c.drawString(2*cm, -3*cm, "%s [%d points]" % (story['Subject'],
# int(float(story['Story points']))))
style.fontSize = 14
style.leading = 16
description = Paragraph(story['Description'], style)
description.wrap(14*cm, 15*cm)
description.drawOn(c, 2*cm, -8*cm)
c.showPage()
return c
开发者ID:afroisalreadyinu,项目名称:redmine-printer,代码行数:29,代码来源:redmine_printer.py
注:本文中的reportlab.platypus.Paragraph类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论