本文整理汇总了Python中reportlab.lib.styles.ParagraphStyle类的典型用法代码示例。如果您正苦于以下问题:Python ParagraphStyle类的具体用法?Python ParagraphStyle怎么用?Python ParagraphStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParagraphStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRml
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')
示例2: build_tabla_totales
def build_tabla_totales(dic_totales):
"""
Construye una tabla con los totales del presupuesto.
La tabla tiene dos columnas. En la primera están las claves del
diccionario «dic_totales». En la segunda los valores correspondientes.
La última fila de la tabla estará en negrita.
Si el diccionario de totales trae una clave "orden" (que debería) se
seguirá ese orden para mostrarlos en las filas.
"""
try:
claves = dic_totales["orden"]
except KeyError:
claves = dic_totales.keys()
datos = []
for clave in claves:
datos += [["", clave, dic_totales[clave]]]
datos[-1][1] = Paragraph("<b>%s</b>" % datos[-1][1],
estilos["BodyText"])
a_derecha = ParagraphStyle("A derecha",
parent = estilos["BodyText"])
a_derecha.alignment = enums.TA_RIGHT
datos[-1][-1] = Paragraph("<b>%s</b>" % datos[-1][-1],
a_derecha)
tabla = Table(datos,
colWidths = (PAGE_WIDTH * 0.55, # HACK: Para que ocupe lo
PAGE_WIDTH * 0.15, # mismo que la otra.
PAGE_WIDTH * 0.2)) # Si no, RL la centra.
tabla.setStyle(TableStyle([
("BOX", (1, 0), (-1, -1), 1.0, colors.black),
("INNERGRID", (1, 0), (-1, -1), 0.25, colors.black),
("ALIGN", (1, 0), (-2, -1), "LEFT"),
("ALIGN", (-1, 0), (-1, -1), "RIGHT"),
]))
return tabla
示例3: getBody
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
示例4: build_encabezado
def build_encabezado(datos_albaran):
"""
Devuelve una tabla de dos líneas con los datos del albarán, que es un
diccionario de: fecha -como texto-, número (de albarán), kilos,
bultos.
"""
datos_albaran = sanitize(datos_albaran)
datos = [["Fecha", escribe("Nº Albarán"), "Kilos", "Bultos"],
[datos_albaran["fecha"], datos_albaran["número"],
datos_albaran["kilos"], datos_albaran["bultos"]]]
estilo_centrado = ParagraphStyle("Alineado centrado",
parent=estilos["Normal"])
estilo_centrado.alignment = enums.TA_CENTER
estilo_centrado.fontSize += 2
datos = [[Paragraph(celda, estilos["Normal"]) for celda in datos[0]] ,
[Paragraph(celda, estilo_centrado) for celda in datos[1]]]
tabla = Table(datos,
colWidths = (PAGE_WIDTH * 0.9/4,)*4)
tabla.setStyle(TableStyle([
("BOX", (0, 1), (-1, -1), 1.0, colors.black),
("INNERGRID", (0, 1), (-1, -1), 0.25, colors.black),
("ALIGN", (0, 0), (-1, 0), "LEFT"),
("ALIGN", (0, 1), (-1, 1), "CENTER"),
]))
return tabla
示例5: cuadritos_en_ruta
def cuadritos_en_ruta():
"""
Devuelve dos flowables:
Un texto centrado con el texto de "ENVASES VACÍOS..." y una tabla
con el texto y los cuadraditos que se rellenan a mano durante la ruta
del transportista.
"""
estilo_centrado = ParagraphStyle("Alineado centrado",
parent=estilos["Normal"])
estilo_centrado.alignment = enums.TA_CENTER
cab = Paragraph(escribe("ENVASES VACÍOS SIN LIMPIAR, 3 A.D.R."),
estilo_centrado)
datos = [["G.R.G. 1.000L", "", "", "BIDONES 100L", ""],
["", "", "", "", ""],
["DEPÓSITO 600L", "", "", "BIDONES 50L", ""],
["", "", "", "", ""],
["BIDONES 200L", "", "", "GARRAFAS 60L", ""],
["", "", "", "", ""],
["BIDONES 25L", "", "", "BIDONES 10L", ""]]
datos = [[escribe(c) for c in fila] for fila in datos]
tabla = Table(datos,
colWidths = (3*cm, 0.75*cm, 5*cm, 3*cm, 0.75*cm))
tabla.setStyle(TableStyle([
("BOX", (1, 0), (1, 0), 1.0, colors.black),
("BOX", (4, 0), (4, 0), 1.0, colors.black),
("BOX", (1, 2), (1, 2), 1.0, colors.black),
("BOX", (4, 2), (4, 2), 1.0, colors.black),
("BOX", (1, 4), (1, 4), 1.0, colors.black),
("BOX", (4, 4), (4, 4), 1.0, colors.black),
("BOX", (1, 6), (1, 6), 1.0, colors.black),
("BOX", (4, 6), (4, 6), 1.0, colors.black),
]))
return KeepTogether([Spacer(1, 0.3*cm), cab, Spacer(1, 0.5*cm), tabla])
示例6: build_tabla_totales
def build_tabla_totales(totales):
"""
Construye una tabla con los totales del albaranSalida.
La tabla tiene dos filas, cabecera y desglose. La variable «totales» es
una lista con los totales *en el siguiente orden*:
base imponible, porcentaje IVA en fracción de 1, y total.
La base imponible incluye los descuentos de las LDVs y demás.
"""
datos = [["Base imponible", "%d%% IVA" % (totales[1]*100), "Total"],
[totales[0], totales[2] - totales[0], totales[2]]]
datos = sanitize(datos)
estilo_numeros_tabla = ParagraphStyle("Números tabla",
parent=estilos["Normal"])
estilo_numeros_tabla.alignment = enums.TA_RIGHT
estilo_numeros_tabla.fontSize += 2
datos = [[Paragraph(celda, estilos["Normal"]) for celda in datos[0]] ,
[Paragraph(celda, estilo_numeros_tabla) for celda in datos[1]]]
tabla = TablaFija(78,
2*cm,
datos,
colWidths = (PAGE_WIDTH * (0.9/3),)*3)
#tabla = Table(datos,
# colWidths = (PAGE_WIDTH * (0.9/3),)*3)
tabla.setStyle(TableStyle([
("BACKGROUND", (0, 0), (-1, 0), colors.lightgrey),
("LINEBELOW", (0, 0), (-1, 0), 1.0, colors.black),
("BOX", (0, 0), (-1, -1), 1.0, colors.black),
("INNERGRID", (0, 0), (-1, -1), 1.0, colors.black),
("ALIGN", (0, 0), (-1, 0), "LEFT"),
]))
return tabla
示例7: tabla_detalle
def tabla_detalle(self):
requerimiento = self.requerimiento
encabezados = ['Nro', 'Cantidad', 'Unidad', u'Descripción', 'Uso']
detalles = DetalleRequerimiento.objects.filter(requerimiento=requerimiento)
sp = ParagraphStyle('parrafos')
sp.alignment = TA_JUSTIFY
sp.fontSize = 8
sp.fontName = "Times-Roman"
lista_detalles = []
for detalle in detalles:
tupla_producto = [Paragraph(str(detalle.nro_detalle), sp),
Paragraph(str(detalle.cantidad), sp),
Paragraph(detalle.producto.unidad_medida.descripcion, sp),
Paragraph(detalle.producto.descripcion, sp),
Paragraph(detalle.uso, sp)]
lista_detalles.append(tupla_producto)
adicionales = [('', '', '', '', '')] * (15 - len(detalles))
tabla_detalle = Table([encabezados] + lista_detalles, colWidths=[0.8 * cm, 2 * cm, 2.5 * cm, 7 * cm, 7.7 * cm])
style = TableStyle(
[
('ALIGN', (0, 0), (4, 0), 'CENTER'),
('GRID', (0, 0), (-1, -1), 1, colors.black),
('FONTSIZE', (0, 0), (-1, -1), 7),
('ALIGN', (4, 1), (-1, -1), 'LEFT'),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
]
)
tabla_detalle.setStyle(style)
return tabla_detalle
示例8: get_content
def get_content(self, column_data, row_values, col_values):
"""return the content formated as defined in the constructor or in the column """
if self.value == None or self.value == False:
return ""
format = self.DEFAULT_FORMAT
if self.format != None:
format = self.format
elif type(column_data) == DateColData and column_data.format != None:
format = column_data.format
value = super(DateCellData,self).get_content(column_data, row_values, col_values)
if format != None:
value = time.strftime(format, value)
else:
value = time.strftime(self.format, value)
ps = ParagraphStyle('date_cell')
ps.fontName = self.get_font(column_data)
ps.fontSize = self.get_font_size(column_data)
ps.alignment = self.get_align_code(column_data)
res = Paragraph(c2c_helper.encode_entities(value), ps)
return res
示例9: 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()
示例10: _add_items
def _add_items(self):
""" add labels and color to the table """
#X starting position
X_pos = 0
if self.title != None:
X_pos = 1
Y_pos = 0
cpt = 0
for i in self.items_order:
#add the label
txt = c2c_helper.encode_entities(self.items[i].label)
ps = ParagraphStyle('color_legend')
ps.alignment = TA_CENTER
ps.fontName = self.DEFAULT_FONT
ps.fontSize = self.DEFAULT_FONT_SIZE
p = Paragraph(txt, ps)
self.table[0][cpt+X_pos] = p
#add the color
self.styles.append(('BACKGROUND', (cpt+X_pos,0), (cpt+X_pos,0), self.items[i].color))
cpt+=1
示例11: build_tabla_contenido
def build_tabla_contenido(data):
"""
Construye la tabla del contenido del albaranSalida.
Los datos deben venir en listas. Cada línea de la tabla, una tupla o lista
con el código, descripción, cantidad, precio unitario (con dto. si lo
lleva e IVA) y número de pedido.
El precio y cantidad deben ser flotantes para poder calcular el subtotal.
"""
estilo_cabecera_tabla = ParagraphStyle("Cabecera tabla",
parent=estilos["Heading3"])
estilo_cabecera_tabla.fontName = "Times-Bold"
estilo_cabecera_tabla.alignment = enums.TA_CENTER
estilo_numeros_tabla = ParagraphStyle("Números tabla",
parent=estilos["Normal"])
estilo_numeros_tabla.alignment = enums.TA_RIGHT
datos = [(Paragraph(escribe("Código"), estilo_cabecera_tabla),
Paragraph(escribe("Descripción"), estilo_cabecera_tabla),
Paragraph("Cantidad", estilo_cabecera_tabla),
Paragraph("Precio/U", estilo_cabecera_tabla),
#Paragraph("Total c/IVA", estilo_cabecera_tabla),
# CWT: Prefiere la carta de portes sin IVA.
Paragraph("Total", estilo_cabecera_tabla),
Paragraph(escribe("Nº Pedido"), estilo_cabecera_tabla))
]
for d in data:
fila = (escribe(d[0]),
Paragraph(escribe(d[1]),estilos["Normal"]),
Paragraph(escribe(utils.float2str(d[2])),estilo_numeros_tabla),
Paragraph(escribe(utils.float2str(d[3])),estilo_numeros_tabla),
Paragraph(escribe(utils.float2str(d[2] * d[3])),
estilo_numeros_tabla),
escribe(d[4])
)
datos.append(fila)
tabla = Table(datos,
colWidths = (PAGE_WIDTH * 0.13,
PAGE_WIDTH * 0.35,
PAGE_WIDTH * 0.09,
PAGE_WIDTH * 0.09,
PAGE_WIDTH * 0.13,
PAGE_WIDTH * 0.11),
repeatRows = 1)
tabla.setStyle(TableStyle([
("BACKGROUND", (0, 0), (-1, 0), colors.lightgrey),
("LINEBEFORE", (0, 0), (-1, -1), 0.25, colors.black),
("LINEBELOW", (0, 0), (-1, 0), 1.0, colors.black),
("LINEBELOW", (0, "splitlast"), (-1, "splitlast"), 1.0, colors.black),
("BOX", (0, 0), (-1, -1), 1.0, colors.black),
("INNERGRID", (0, 0), (-1, -1), 0.25, colors.black),
("VALIGN", (0, 0), (-1, 0), "CENTER"),
("VALIGN", (0, 0), (0, -1), "TOP"),
("ALIGN", (0, 0), (-1, 0), "CENTER"),
("ALIGN", (-3, 1), (-1, -1), "RIGHT"),
#("ALIGN", (0, 1), (0, -1), "DECIMAL"), <- No puedo cambiar
# el pivotChar de "." a ",". No me vale.
("ALIGN", (-1, 1), (-1, -1), "CENTER"),
("ALIGN", (0, 1), (0, -1), "CENTER"),
#("RIGHTPADDING", (0, 1), (0, -1), 0.75 * cm),
]))
return tabla
示例12: _build_table
def _build_table(self):
""" return the list of list that represent the table structure """
line = []
if self.title != None:
txt = c2c_helper.encode_entities(self.title)
ps = ParagraphStyle('color_legend')
ps.alignment = TA_CENTER
ps.fontName = self.DEFAULT_FONT
ps.fontSize = self.DEFAULT_FONT_SIZE
p = Paragraph(txt, ps)
line.append([p])
for i in self.items_order:
line.append('')
self.table.append(line)
#global font for the whole graphic
self.styles.append(('FONT', (0,0), (-1,-1),self.DEFAULT_FONT, self.DEFAULT_FONT_SIZE))
# main frame arround the whole table
self.styles.append(('BOX', (0,0), (-1,-1), 1, "#000000"))
#in cells, text start in the top left corner
self.styles.append(('VALIGN', (0,0), (-1,-1), 'TOP'))
if self.title != None:
#background of the legend title
self.styles.append(('BACKGROUND', (0,0), (0,0), "#cccccc"))
示例13: _add_Y_items
def _add_Y_items(self):
""" add Y items labels to the chart (Text and styles). Add also light grid for their lines """
X_pos = 0
Y_pos = 3
# draw the items titles with the right indentation
for i in self.data.items_order:
item = self.data.items[i]
ps = ParagraphStyle("indent")
ps.fontName = self.DEFAULT_FONT
ps.fontSize = self.DEFAULT_FONT_SIZE
ps.leftIndent = item.indent * self.INDENT_SPACE
p = Paragraph(self._encode_entities(item.label), ps)
self.table[Y_pos + item.Y_pos][X_pos] = p
# draw the inner grid for this lines
start_X = X_pos
end_X = -1
start_Y = Y_pos + item.Y_pos
end_Y = Y_pos + item.Y_pos + item.line_number
self.styles.append(("LINEABOVE", (start_X, end_Y), (end_X, end_Y), 0.2, "#bbbbbb"))
self.styles.append(("LINEAFTER", (start_X, start_Y), (end_X, end_Y), 0.2, "#bbbbbb"))
# line that separate the Y items and the datas
self.styles.append(("LINEAFTER", (X_pos, Y_pos - 2), (X_pos, -1), 1, colors.black))
示例14: build_datos_cliente
def build_datos_cliente(datos_cliente = []):
"""
Devuelve una lista de Flowables con las líneas recibidas como texto.
"""
datos_c = []
estilo_datos_c = ParagraphStyle("Cliente",
parent = estilos["Heading3"])
estilo_datos_c.alignment = enums.TA_RIGHT
estilo_datos_c.spaceAfter = estilo_datos_c.spaceBefore = 2
if datos_cliente:
try:
datos_cliente[0] = "<strong>%s</strong>" % datos_cliente[0]
except TypeError:
datos_cliente = ["<strong>%s</strong>" % datos_cliente[0]] \
+ list(datos_cliente[1:])
tamanno_predeterminado = estilo_datos_c.fontSize
for linea in datos_cliente:
# ¡Esto debería hacerlo ReportLab, pero no sé por qué el markup
# sólo funciona con el estilo normal!
if "<strong>" in linea:
estilo_datos_c.fontSize += 4
else:
estilo_datos_c.fontSize = tamanno_predeterminado
p = Paragraph(escribe(linea), estilo_datos_c)
datos_c.append(p)
return datos_c
示例15: _content
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