本文整理汇总了Python中reportlab.lib.styles.ParagraphStyle.spaceBefore方法的典型用法代码示例。如果您正苦于以下问题:Python ParagraphStyle.spaceBefore方法的具体用法?Python ParagraphStyle.spaceBefore怎么用?Python ParagraphStyle.spaceBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.lib.styles.ParagraphStyle
的用法示例。
在下文中一共展示了ParagraphStyle.spaceBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_encabezado
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def build_encabezado(datos_empresa = []):
"""
Devuelve una lista de "Flowables" de reportlab con los datos de la empresa.
Los datos de la empresa se reciben como una lista de textos.
"""
cabecera = []
estilo_encabezado = ParagraphStyle("Encabezado",
parent = estilos["Heading2"])
estilo_encabezado.rightIndent = PAGE_WIDTH * 0.25
estilo_encabezado.alignment = enums.TA_JUSTIFY
estilo_encabezado.spaceAfter = 0
estilo_encabezado.spaceBefore = 4
datos_empresa[0] = datos_empresa[0].upper()
for linea in datos_empresa:
if linea is datos_empresa[0]:
estilo_encabezado.fontSize += 3
p = Paragraph(escribe(linea), estilo_encabezado)
cabecera.append(p)
estilo_encabezado.fontSize -= 1
if estilo_encabezado.spaceAfter > -4:
estilo_encabezado.spaceAfter -= 1
estilo_encabezado.spaceBefore = estilo_encabezado.spaceAfter
if linea is datos_empresa[0]:
estilo_encabezado.fontSize -= 3
return cabecera
示例2: testRml
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def testRml():
from reportlab.platypus.doctemplate import SimpleDocTemplate
from reportlab.platypus.flowables import Spacer
from reportlab.lib.randomtext import randomText
templ = SimpleDocTemplate('doclet_output.pdf')
#need a style
story = []
normal = ParagraphStyle('normal')
normal.firstLineIndent = 18
normal.spaceBefore = 6
para = Paragraph("Test of doclets. You should see a little table with a reversed word.", normal)
story.append(para)
story.append(Spacer(36,36))
theDoclet = TestReverseDoclet()
story.append(theDoclet.asFlowable())
for i in range(5):
para = Paragraph(randomText(), normal)
story.append(para)
templ.build(story)
print('saved doclet_output.pdf')
示例3: toParagraphStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def toParagraphStyle(self, first, full=False):
style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.leading = max(first.leading, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.textColor = first.textColor
style.alignment = first.alignment
style.bulletFontName = first.bulletFontName or first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
# Border handling for Paragraph
style.borderWidth = 0
if getBorderStyle(first.borderTopStyle):
style.borderWidth = max(first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth)
style.borderPadding = first.borderPadding # + first.borderWidth
style.borderColor = first.borderTopColor
# If no border color is given, the text color is used (XXX Tables!)
if (style.borderColor is None) and style.borderWidth:
style.borderColor = first.textColor
if full:
style.fontName = tt2ps(first.fontName, first.bold, first.italic)
return style
示例4: getBody
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def getBody(self, story=None):
story = story or self._story
header_style = ParagraphStyle(name='header_style', fontSize=12, alignment=TA_CENTER)
story.append(Paragraph('<b>{}</b>'.format(_('List of sessions')), header_style))
text_style = ParagraphStyle(name='text_style', fontSize=8, alignment=TA_LEFT, leading=10, leftIndent=10)
text_style.fontName = 'Times-Roman'
text_style.spaceBefore = 0
text_style.spaceAfter = 0
text_style.firstLineIndent = 0
rows = []
row_values = []
for col in [_('ID'), _('Type'), _('Title'), _('Code'), _('Description')]:
row_values.append(Paragraph('<b>{}</b>'.format(col), text_style))
rows.append(row_values)
for sess in self.sessions:
rows.append([
Paragraph(sess.friendly_id, text_style),
Paragraph(_('Poster') if sess.is_poster else _('Standard'), text_style),
Paragraph(sess.title.encode('utf-8'), text_style),
Paragraph(sess.code.encode('utf-8'), text_style),
Paragraph(sess.description.encode('utf-8'), text_style)
])
col_widths = (None,) * 5
table_style = TableStyle([
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('LINEBELOW', (0, 0), (-1, 0), 1, colors.black),
('ALIGN', (0, 0), (-1, 0), 'CENTER'),
('ALIGN', (0, 1), (-1, -1), 'LEFT')
])
story.append(Table(rows, colWidths=col_widths, style=table_style))
return story
示例5: addPara
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def addPara(self, force=False):
# Cleanup the trail
for frag in reversed(self.fragList):
frag.text = frag.text.rstrip()
if frag.text:
break
if force or (self.text.strip() and self.fragList):
# Strip trailing whitespaces
# for f in self.fragList:
# f.text = f.text.lstrip()
# if f.text:
# break
# self.fragList[-1].lineBreak = self.fragList[-1].text.rstrip()
# Update paragraph style by style of first fragment
first = self.fragBlock
style = ParagraphStyle("default%d" % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.leading = max(first.leading, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.alignment = first.alignment
style.bulletFontName = first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
style.borderWidth = max(
first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth
)
style.borderPadding = first.borderPadding # + first.borderWidth
style.borderColor = first.borderTopColor
# borderRadius: None,
# print repr(self.text.strip()), style.leading, "".join([repr(x.text) for x in self.fragList])
# print first.leftIndent, first.listStyleType,repr(self.text)
# Add paragraph to story
para = PmlParagraph(
self.text, style, frags=self.fragAnchor + self.fragList, bulletText=copy.copy(first.bulletText)
)
para.outline = frag.outline
para.outlineLevel = frag.outlineLevel
para.outlineOpen = frag.outlineOpen
self.addStory(para)
self.fragAnchor = []
first.bulletText = None
self.clearFrag()
示例6: _content
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def _content(self):
# TODO: move styles somewhere else
# style for additional information box
ibs = ParagraphStyle('inputBoxStyle',styles['Message'])
ibs.fontName = 'Courier'
ibs.leftIndent = cm
ibs.spaceBefore = 0.2*cm
ibs.spaceAfter = 0.5*cm
# font style for letter subject
styles['Subject'].fontName = 'Helvetica-Bold'
content = [
Paragraph(_("auskunft_subject"), styles['Subject']),
Paragraph(_("auskunft_greeting"), styles['Greeting']),
Spacer(0,0.5*cm),
Paragraph(_("auskunft_question_text"), styles['Message']),
ListFlowable([
ListItem(Paragraph(_("auskunft_question_1"),styles['Message'])),
ListItem(Paragraph(_("auskunft_question_2"),styles['Message'])),
ListItem(Paragraph(_("auskunft_question_3"),styles['Message'])),
ListItem(Paragraph(_("auskunft_question_4"),styles['Message'])),
],
bulletType='bullet',
start='square'
),
Paragraph(_("auskunft_reference"), styles['Message']),
Paragraph(_("auskunft_par_10"), styles['Message']),
Paragraph(_("auskunft_par_4"), styles['Message']),
Paragraph(_("auskunft_par_12"), styles['Message']),
Paragraph(_("auskunft_standard_application"), styles['Message'])
]
# Registered Applications
if self.table_apps:
content += [
Paragraph(_("auskunft_registered_application_pre"),styles['Message']),
self.table_apps,
Paragraph(_("auskunft_registered_application_post"),styles['Message'])
]
# Additional Information
if self.add_info:
content += [
Paragraph(_("auskunft_additional_info_text"), styles['Message']),
Paragraph(self.add_info,ibs)
]
content += [
Paragraph(_("auskunft_method_identity"),styles['Message']),
Paragraph(_("auskunft_expected_response"),styles['Message']),
Spacer(0,0.5*cm),
Paragraph(_("auskunft_signature"),styles['Signature']),
Spacer(0,1.5*cm),
Paragraph(self.sender_name,styles['Signature'])
]
return content
示例7: toParagraphStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def toParagraphStyle(self, first):
style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.letterSpacing = first.letterSpacing
style.leading = max(first.leading + first.leadingSpace, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.textColor = first.textColor
style.alignment = first.alignment
style.bulletFontName = first.bulletFontName or first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
style.wordWrap = first.wordWrap
# Border handling for Paragraph
# Transfer the styles for each side of the border, *not* the whole
# border values that reportlab supports. We'll draw them ourselves in
# PmlParagraph.
style.borderTopStyle = first.borderTopStyle
style.borderTopWidth = first.borderTopWidth
style.borderTopColor = first.borderTopColor
style.borderBottomStyle = first.borderBottomStyle
style.borderBottomWidth = first.borderBottomWidth
style.borderBottomColor = first.borderBottomColor
style.borderLeftStyle = first.borderLeftStyle
style.borderLeftWidth = first.borderLeftWidth
style.borderLeftColor = first.borderLeftColor
style.borderRightStyle = first.borderRightStyle
style.borderRightWidth = first.borderRightWidth
style.borderRightColor = first.borderRightColor
# If no border color is given, the text color is used (XXX Tables!)
if (style.borderTopColor is None) and style.borderTopWidth:
style.borderTopColor = first.textColor
if (style.borderBottomColor is None) and style.borderBottomWidth:
style.borderBottomColor = first.textColor
if (style.borderLeftColor is None) and style.borderLeftWidth:
style.borderLeftColor = first.textColor
if (style.borderRightColor is None) and style.borderRightWidth:
style.borderRightColor = first.textColor
style.borderPadding = first.borderPadding
style.paddingTop = first.paddingTop
style.paddingBottom = first.paddingBottom
style.paddingLeft = first.paddingLeft
style.paddingRight = first.paddingRight
style.fontName = tt2ps(first.fontName, first.bold, first.italic)
return style
示例8: build_encabezado
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def build_encabezado(datos_empresa = []):
"""
Devuelve una lista de "Flowables" de reportlab con los datos de la empresa.
Los datos de la empresa se reciben como una lista de textos.
"""
cabecera = []
estilo_encabezado = ParagraphStyle("Encabezado",
parent = estilos["Heading2"])
estilo_encabezado.rightIndent = PAGE_WIDTH * 0.4
estilo_encabezado.alignment = enums.TA_CENTER
estilo_encabezado.spaceAfter = estilo_encabezado.spaceBefore = 6
for linea in datos_empresa:
p = Paragraph(escribe(linea), estilo_encabezado)
cabecera.append(p)
estilo_encabezado.fontSize -= 1
if estilo_encabezado.spaceAfter > 0:
estilo_encabezado.spaceAfter -= 1
estilo_encabezado.spaceBefore = estilo_encabezado.spaceAfter
return cabecera
示例9: _prepareTOC
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def _prepareTOC(self):
headerStyle = ParagraphStyle({})
headerStyle.fontName = "LinuxLibertine-Bold"
headerStyle.fontSize = modifiedFontSize(18, 18)
headerStyle.leading = modifiedFontSize(22, 22)
headerStyle.alignment = TA_CENTER
entryStyle = ParagraphStyle({})
entryStyle.fontName = "LinuxLibertine"
entryStyle.spaceBefore = 8
self._tocStory.append(PageBreak())
if self.include_toc:
self._tocStory.append(Spacer(inch, 1*cm))
self._tocStory.append(Paragraph(_("Table of contents"), headerStyle))
self._tocStory.append(Spacer(inch, 2*cm))
for entry in self._toc:
indent = ((entry[0] - 1) * 50)
toc_entry = TableOfContentsEntry('<para leftIndent={}>{}</para>'.format(indent, entry[1]),
str(entry[2]), entryStyle)
self._tocStory.append(toc_entry)
示例10: run
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def run():
objects_to_draw = []
from reportlab.lib.styles import ParagraphStyle
#from paragraph import Paragraph
from doctemplate import SimpleDocTemplate
#need a style
normal = ParagraphStyle('normal')
normal.firstLineIndent = 18
normal.spaceBefore = 6
from reportlab.lib.randomtext import randomText
import random
for i in range(15):
height = 0.5 + (2*random.random())
box = XBox(6 * inch, height * inch, 'Box Number %d' % i)
objects_to_draw.append(box)
para = Paragraph(randomText(), normal)
objects_to_draw.append(para)
SimpleDocTemplate('doctemplate.pdf').build(objects_to_draw,
onFirstPage=myFirstPage,onLaterPages=myLaterPages)
示例11: ParagraphStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
from courseevaluations.models import QuestionSet, MultipleChoiceQuestionAnswer, FreeformQuestionAnswer
title_style = ParagraphStyle(getSampleStyleSheet()["Normal"])
question_set_style = ParagraphStyle(getSampleStyleSheet()["Normal"])
question_style = ParagraphStyle(getSampleStyleSheet()["Normal"])
multiple_choice_option_style = ParagraphStyle(getSampleStyleSheet()["Normal"])
multiple_choice_count_style = ParagraphStyle(getSampleStyleSheet()["Normal"])
freeform_answer_style = ParagraphStyle(getSampleStyleSheet()["Normal"])
title_style.fontSize = 20
title_style.leading = 24
title_style.alignment = enums.TA_RIGHT
title_style.fontName = 'Times-BoldItalic'
question_style.spaceBefore = 10
question_style.fontName = 'Times-Bold'
question_style.fontSize = 12
multiple_choice_option_style.alignment = enums.TA_CENTER
multiple_choice_count_style.alignment = enums.TA_CENTER
freeform_answer_style.fontSize = 8
def build_report(output, evaluables, title=None, comments=True, unmask_comments=False):
doc_args = {
'author': 'Rectory School Evaluation System',
'pagesize': letter,
'leftMargin': 36,
'rightMargin': 36,
}
示例12: getExamples
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def getExamples():
"""Returns all the example flowable objects"""
styleSheet = getSampleStyleSheet()
story = []
#make a style with indents and spacing
sty = ParagraphStyle('obvious', None)
sty.leftIndent = 18
sty.rightIndent = 18
sty.firstLineIndent = 18
sty.spaceBefore = 6
sty.spaceAfter = 6
story.append(Paragraph("""Now for some demo stuff - we need some on this page,
even before we explain the concepts fully""", styleSheet['BodyText']))
p = Paragraph("""
Platypus is all about fitting objects into frames on the page. You
are looking at a fairly simple Platypus paragraph in Debug mode.
It has some gridlines drawn around it to show the left and right indents,
and the space before and after, all of which are attributes set in
the style sheet. To be specific, this paragraph has left and
right indents of 18 points, a first line indent of 36 points,
and 6 points of space before and after itself. A paragraph
object fills the width of the enclosing frame, as you would expect.""", sty)
p.debug = 1 #show me the borders
story.append(p)
story.append(Paragraph("""Same but with justification 1.5 extra leading and green text.""", styleSheet['BodyText']))
p = Paragraph("""
<para align=justify leading=+1.5 fg=green><font color=red>Platypus</font> is all about fitting objects into frames on the page. You
are looking at a fairly simple Platypus paragraph in Debug mode.
It has some gridlines drawn around it to show the left and right indents,
and the space before and after, all of which are attributes set in
the style sheet. To be specific, this paragraph has left and
right indents of 18 points, a first line indent of 36 points,
and 6 points of space before and after itself. A paragraph
object fills the width of the enclosing frame, as you would expect.</para>""", sty)
p.debug = 1 #show me the borders
story.append(p)
story.append(platypus.XBox(4*inch, 0.75*inch,
'This is a box with a fixed size'))
story.append(Paragraph("""
All of this is being drawn within a text frame which was defined
on the page. This frame is in 'debug' mode so you can see the border,
and also see the margins which it reserves. A frame does not have
to have margins, but they have been set to 6 points each to create
a little space around the contents.
""", styleSheet['BodyText']))
story.append(FrameBreak())
#######################################################################
# Examples Page 2
#######################################################################
story.append(Paragraph("""
Here's the base class for Flowable...
""", styleSheet['Italic']))
code = '''class Flowable:
"""Abstract base class for things to be drawn. Key concepts:
1. It knows its size
2. It draws in its own coordinate system (this requires the
base API to provide a translate() function.
"""
def __init__(self):
self.width = 0
self.height = 0
self.wrapped = 0
def drawOn(self, canvas, x, y):
"Tell it to draw itself on the canvas. Do not override"
self.canv = canvas
self.canv.saveState()
self.canv.translate(x, y)
self.draw() #this is the bit you overload
self.canv.restoreState()
del self.canv
def wrap(self, availWidth, availHeight):
"""This will be called by the enclosing frame before objects
are asked their size, drawn or whatever. It returns the
size actually used."""
return (self.width, self.height)
'''
story.append(Preformatted(code, styleSheet['Code'], dedent=4))
story.append(FrameBreak())
#######################################################################
# Examples Page 3
#######################################################################
story.append(Paragraph(
"Here are some examples of the remaining objects above.",
#.........这里部分代码省略.........
示例13: toParagraphStyle
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def toParagraphStyle(self, first, full=False):
style = ParagraphStyle('default%d' % self.UID(), keepWithNext=first.keepWithNext)
style.fontName = first.fontName
style.fontSize = first.fontSize
style.leading = max(first.leading, first.fontSize * 1.25)
style.backColor = first.backColor
style.spaceBefore = first.spaceBefore
style.spaceAfter = first.spaceAfter
style.leftIndent = first.leftIndent
style.rightIndent = first.rightIndent
style.firstLineIndent = first.firstLineIndent
style.textColor = first.textColor
style.alignment = first.alignment
style.bulletFontName = first.bulletFontName or first.fontName
style.bulletFontSize = first.fontSize
style.bulletIndent = first.bulletIndent
# Border handling for Paragraph
# Transfer the styles for each side of the border, *not* the whole
# border values that reportlab supports. We'll draw them ourselves in
# PmlParagraph.
style.borderTopStyle = first.borderTopStyle
style.borderTopWidth = first.borderTopWidth
style.borderTopColor = first.borderTopColor
style.borderBottomStyle = first.borderBottomStyle
style.borderBottomWidth = first.borderBottomWidth
style.borderBottomColor = first.borderBottomColor
style.borderLeftStyle = first.borderLeftStyle
style.borderLeftWidth = first.borderLeftWidth
style.borderLeftColor = first.borderLeftColor
style.borderRightStyle = first.borderRightStyle
style.borderRightWidth = first.borderRightWidth
style.borderRightColor = first.borderRightColor
# If no border color is given, the text color is used (XXX Tables!)
if (style.borderTopColor is None) and style.borderTopWidth:
style.borderTopColor = first.textColor
if (style.borderBottomColor is None) and style.borderBottomWidth:
style.borderBottomColor = first.textColor
if (style.borderLeftColor is None) and style.borderLeftWidth:
style.borderLeftColor = first.textColor
if (style.borderRightColor is None) and style.borderRightWidth:
style.borderRightColor = first.textColor
style.borderPadding = first.borderPadding
style.paddingTop = first.paddingTop
style.paddingBottom = first.paddingBottom
style.paddingLeft = first.paddingLeft
style.paddingRight = first.paddingRight
# This is the old code replaced by the above, kept for reference
#style.borderWidth = 0
#if getBorderStyle(first.borderTopStyle):
# style.borderWidth = max(first.borderLeftWidth, first.borderRightWidth, first.borderTopWidth, first.borderBottomWidth)
# style.borderPadding = first.borderPadding # + first.borderWidth
# style.borderColor = first.borderTopColor
# # If no border color is given, the text color is used (XXX Tables!)
# if (style.borderColor is None) and style.borderWidth:
# style.borderColor = first.textColor
if full:
style.fontName = tt2ps(first.fontName, first.bold, first.italic)
return style
示例14: createPDF
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
#.........这里部分代码省略.........
('GRID', (c_index,r_index), (c_max,r_max), 0.5, grid),
('FONTNAME', (c_index,r_index), (c_index,r_index), 'Times-Roman'),
('FONTSIZE', (c_index,r_index), (c_index,r_index), 9),
('LEFTPADDING', (c_index,r_index), (c_index,r_index), 3),
('RIGHTPADDING', (c_index,r_index), (c_index,r_index), 3),
('SPAN', (c_index,r_index), (c_max,r_max)),
('ALIGN', (c_index,r_index), (c_index,r_index), td_align),
]
)
c_index = c_index + 1
table_data.append(table_row)
r_index = r_index + 1
caption = item.find('caption')
return (table_data, TableStyle(table_style), caption)
# Provides the PDF entities for the corresponding HTML tags.
def getContent(item, bump_headings=False):
pdf = []
if isinstance(item, Tag):
className=item.get('class', '').split()
item_type = item.name
if item_type in ['h2', 'h3', 'h4', 'h5', 'h6']:
item_style = tag_to_style.get(item_type)
h = Paragraph(getItemText(item), styles[item_style])
h.keepWithNext = True
pdf.append(h)
if item_type == 'h2' and not bump_headings:
hr = HRFlowable(width='100%', thickness=0.25, spaceBefore=2, spaceAfter=4, color=styles[item_style].textColor)
hr.keepWithNext = True
pdf.append(hr)
elif item_type in ['table']:
(table_data, table_style, caption) = getTableData(item)
table = Table(table_data)
table.setStyle(table_style)
table.hAlign = 'LEFT'
table.spaceBefore = 10
table.spaceAfter = 10
if caption:
caption_el = Paragraph(getInlineContents(caption), discreet)
pdf.append(KeepTogether([table, caption_el]))
else:
pdf.append(table)
elif item_type in ['ul']:
for i in item.findAll('li'):
pdf.append(Paragraph('<bullet>•</bullet>%s' % getInlineContents(i), bullet_list))
elif item_type in ['ol']:
# Sequences were incrementing based on previous PDF generations.
# Including explicit ID and reset
li_uuid = uuid1().hex
for i in item.findAll('li'):
pdf.append(Paragraph('<seq id="%s" />. %s' % (li_uuid, getInlineContents(i)), bullet_list))
pdf.append(Paragraph('<seqReset id="%s" />' % li_uuid, styles['Normal']))
elif item_type in ['p'] or (item_type in ['div'] and 'captionedImage' in className or 'callout' in className or 'pullquote' in className):
has_image = False
# Pull images out of items and add before
for img in item.findAll('img'):
示例15: rebStyleSeet
# 需要导入模块: from reportlab.lib.styles import ParagraphStyle [as 别名]
# 或者: from reportlab.lib.styles.ParagraphStyle import spaceBefore [as 别名]
def rebStyleSeet():
"""Return realestatebroker stylesheet."""
stylesheet = {}
colors = rebColors()
fonts = {'LuxiSans': 'luxisr.ttf',
'LuxiSansOblique': 'luxisri.ttf',
'LuxiSansBold': 'luxisb.ttf',
'LuxiSansBoldOblique': 'luxisbi.ttf'}
for name, fn in fonts.items():
filename = os.path.join(os.path.dirname(__file__), fn)
pdfmetrics.registerFont(TTFont(name, filename))
addMapping('LuxiSans', 0, 0, 'LuxiSans') #normal
addMapping('LuxiSans', 0, 1, 'LuxiSansOblique') #italic
addMapping('LuxiSans', 1, 0, 'LuxiSansBold') #bold
addMapping('LuxiSans', 1, 1, 'LuxiSansBoldOblique') #italic and bold
normal_font = 'LuxiSans'
bold_font = 'LuxiSansBold'
# Huge is for the huge "for sale" text on the default frontpage.
huge = ParagraphStyle('huge')
huge.fontSize = 48
huge.leading = 50
huge.spaceAfter = 0
huge.fontName = bold_font
stylesheet['huge'] = huge
# Big: large text on the front page and for the address at the end.
big = ParagraphStyle('big')
big.fontSize = 24
big.leading = 26
big.spaceAfter = 10
big.fontName = bold_font
stylesheet['big'] = big
# Footer: small text at the bottom of every page.
footer = ParagraphStyle('footer')
footer.fontSize = 10
footer.spaceAfter = 0
footer.fontName = normal_font
stylesheet['footer'] = footer
# Normal: normal text
normal = ParagraphStyle('normal')
normal.fontSize = 12
normal.leading = 14
normal.spaceAfter = 12
normal.fontName = normal_font
stylesheet['normal'] = normal
# Description: description text, you might want to have this bold or so.
description = ParagraphStyle('description')
description.fontSize = 16
description.leading = 18
description.spaceAfter = 16
description.fontName = bold_font
stylesheet['description'] = description
# Heading1: heading1 text
heading1 = ParagraphStyle('heading1')
heading1.fontSize = 16
heading1.leading = 18
heading1.spaceAfter = 16
heading1.fontName = bold_font
stylesheet['heading1'] = heading1
# Heading2: heading2 text
heading2 = ParagraphStyle('heading2')
heading2.fontSize = 12
heading2.leading = 14
heading2.spaceAfter = 0
heading2.spaceBefore = 14
heading2.fontName = bold_font
stylesheet['heading2'] = heading2
# Table_header: table header text.
table_header = ParagraphStyle('table_header')
table_header.fontSize = 12
table_header.leading = 14
table_header.spaceAfter = 0
table_header.fontName = bold_font
table_header.textColor = colors['table_heading_textcolor']
stylesheet['table_header'] = table_header
# Table_text: table text.
table_text = ParagraphStyle('table_text')
table_text.fontSize = 10
table_text.leading = 12
table_text.spaceAfter = 0
table_text.fontName = normal_font
stylesheet['table_text'] = table_text
utility = queryUtility(IStyleModifier)
if not utility:
return stylesheet
else:
return utility(stylesheet)