def get(self, request, *args, **kwargs):
response = HttpResponse(content_type='application/pdf')
pdf_name = "clientes.pdf" # llamado clientes
# la linea 26 es por si deseas descargar el pdf a tu computadora
# response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=40,
leftMargin=40,
topMargin=60,
bottomMargin=18,
)
clientes = []
styles = getSampleStyleSheet()
header = Paragraph("Listado de Clientes", styles['Heading1'])
clientes.append(header)
headings = ('Nombre', 'Email', 'Edad', 'Direccion')
allclientes = [(p.codigo, p.descripcion, p.precio_mercado, p.grupo_suministros) for p in Producto.objects.all()]
t = Table([headings] + allclientes)
t.setStyle(TableStyle(
[
('GRID', (0, 0), (3, -1), 1, colors.dodgerblue),
('LINEBELOW', (0, 0), (-1, 0), 2, colors.darkblue),
('BACKGROUND', (0, 0), (-1, 0), colors.dodgerblue)
]
))
clientes.append(t)
doc.build(clientes)
response.write(buff.getvalue())
buff.close()
return response
python类Table()的实例源码
def _posting_list_table(self, canvas, x1, y1, x2, y2, shipping_labels):
style = self.table_style[:]
table = [self.table_header]
for i, shipping_label in enumerate(shipping_labels, start=1):
row = (
str(shipping_label.tracking_code),
str(shipping_label.receiver.zip_code),
str(shipping_label.package.posting_weight),
self.yes if ExtraService.get(EXTRA_SERVICE_AR) in shipping_label else self.no,
self.yes if ExtraService.get(EXTRA_SERVICE_MP) in shipping_label else self.no,
self.yes if ExtraService.get(EXTRA_SERVICE_VD) in shipping_label else self.no,
str(shipping_label.value).replace(".", ",") if shipping_label.value is not None else "",
str(shipping_label.invoice_number),
shipping_label.get_package_sequence(),
shipping_label.receiver.name[:self.max_receiver_name_size],
)
# noinspection PyTypeChecker
table.append(row)
if i % 2:
style.append(('BACKGROUND', (0, i), (-1, i), colors.lightgrey))
table_flow = Table(
table,
colWidths=self.col_widths,
style=TableStyle(style),
)
w, h = table_flow.wrap(0, 0)
table_flow.drawOn(canvas, x1, y2 - h - 50 * mm)
def test_08_table(self):
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Spacer, Paragraph, Table
from reportlab.lib.units import inch
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib import fonts, colors
pdfmetrics.registerFont(TTFont('chsFont', 'STHeiti Light.ttc'))
stylesheet = getSampleStyleSheet()
elements = []
doc = SimpleDocTemplate("demo.pdf")
elements.append(Paragraph('<font name="chsFont">AUT OOM????</font>', stylesheet['Title']))
elements.append(Spacer(1,12))
stylesheet.add(ParagraphStyle(name="Justify", alignment=TA_JUSTIFY))
stylesheet['Justify'].contName = 'chsFont'
data = []
data.append(["???","???","???"])
data.append(["120","6","50"])
ts = [('INNERGRID',(0,0),(-1,-1),0.25, colors.black),("BOX",(0,0),(-1,-1),0.25,colors.black),('FONT',(0,0),(-1,-1), 'chsFont')]
table = Table(data, 2.1*inch, 0.24*inch, ts)
elements.append(table)
doc.build(elements)
def add_table_content(self, head, data, rowHeights=[30,14], colWidths=[80], style=None):
'''
????
:param head: ????(???)
:param data: ????
:param rowHeights: ?? ??,[30, 14*len(data)]
:param colWidths: ?? ??,[80* len(data)]
:param style: ??, ??:???,????,?????,10?????,??0.5???
'''
__table_data = [head]
__table_data.append(data)
if style == None:
__sty = [
('ALIGN',(0,0),(-1,-1),'LEFT'),
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('BACKGROUND',(0,0),(-1,0),colors.lightblue),
('FONT',(0,0),(-1,0),'chsFont'),
('SIZE',(0,0),(-1,0),10),
('GRID',(0,0),(-1,-1),0.5,colors.black),
('RIGHTPADDING',(0,0),(-1,-1),0),
]
t=Table(__table_data,
rowHeights=[rowHeights[0],].extend([rowHeights[1]]*len(data)),
colWidths=(lambda x: x==[80] and x.extend(x*len(head)) or x)(colWidths),
style=__sty,
)
self.__content.append(t)
def AddPage(self):
self.Score_Table=Table(self.Score_Data,[self.cW1*cm]+8*[self.cW*cm], [self.rH1*cm]+[self.rH2*cm]+14*[self.rH*cm])
#self.Attendance_Table=Table(self.Attendance_Data,[self.cW*2.2*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Attendance_Table=Table(self.Attendance_Data,[self.cW1*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Score_Table.setStyle(TableStyle(self.Score_T_Style))
self.Attendance_Table.setStyle(TableStyle(self.Attendance_T_Style))
self.elements.append(self.Score_Table)
self.elements.append(Spacer(1, 15))
self.elements.append(self.Attendance_Table)
self.elements.append(PageBreak())
def AddPage(self):
#self.Score_Table=Table(self.Score_Data,[.3*inch]+[1*inch]+8*[0.6*inch], [.8*inch]+[.6*inch]+14*[0.35*inch])
self.Score_Table=Table(self.Score_Data,[.5*inch]+[(self.cW1*cm)-.5*inch]+8*[self.cW*cm], [self.rH1*cm]+[self.rH2*cm]+14*[self.rH*cm])
self.Attendance_Table=Table(self.Attendance_Data,[self.cW*2.2*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Score_Table.setStyle(TableStyle(self.Score_T_Style))
self.Attendance_Table.setStyle(TableStyle(self.Attendance_T_Style))
self.elements.append(self.Score_Table)
self.elements.append(Spacer(1, 18))
self.elements.append(self.Attendance_Table)
self.elements.append(PageBreak())
def AddPage(self):
#self.Score_Table=Table(self.Score_Data,[.3*inch]+[1*inch]+8*[0.6*inch], [.8*inch]+[.6*inch]+14*[0.35*inch])
self.Score_Table=Table(self.Score_Data,[.5*inch]+[(self.cW1*cm)-.5*inch]+8*[self.cW*cm], [self.rH1*cm]+[self.rH2*cm]+14*[self.rH*cm])
self.Attendance_Table=Table(self.Attendance_Data,[self.cW*2.2*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Score_Table.setStyle(TableStyle(self.Score_T_Style))
self.Attendance_Table.setStyle(TableStyle(self.Attendance_T_Style))
self.elements.append(self.Score_Table)
self.elements.append(Spacer(1, 18))
self.elements.append(self.Attendance_Table)
self.elements.append(PageBreak())
def SetTable_Style(self):
#Starts Score Table
self.Each_Pupil_Style=[('BOX',(0,0),(-1,-1),1.7,colors.black),
('GRID',(0,0),(-1,-1),1,colors.black),#
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('ALIGN',(0,0),(-1,-1),'CENTER'),
('FONTSIZE',(0,0),(-1,-1),8),
('SPAN',(0,0),(0,-1)), # Roll
('SPAN',(1,0),(1,-1)), # Ad_no
('SPAN',(2,0),(2,-1)), # Name
('SPAN',(57,0),(57,-1)), # Attendance
('SPAN',(58,0),(58,-1)), # promo
('SPAN',(59,0),(59,-1)), # Basis
('SPAN',(60,0),(60,-1)) , # Remark
('SPAN',(4,0),(4,-1)) , # Remark
('BOX',(0,0),(4,3),1.5,colors.black), # Subject Blocks
('BOX',(5,0),(8,3),1.5,colors.black),
('BOX',(9,0),(12,3),1.5,colors.black),
('BOX',(13,0),(16,3),1.5,colors.black),
('BOX',(17,0),(20,3),1.5,colors.black),
('BOX',(21,0),(24,3),1.5,colors.black),
('BOX',(25,0),(28,3),1.5,colors.black),
('BOX',(29,0),(32,3),1.5,colors.black),
('BOX',(33,0),(36,3),1.5,colors.black),
('BOX',(37,0),(40,3),1.5,colors.black),
('BOX',(41,0),(45,3),1.5,colors.black), # IT with practical
('BOX',(46,0),(51,3),1.5,colors.black),
('BOX',(52,0),(56,3),1.5,colors.black),
('BOX',(53,0),(54,3),1.2,colors.black),# % and all
('BOX',(55,0),(56,3),1.2,colors.black),
('BOX',(57,0),(58,3),1.2,colors.black),
('BOX',(59,0),(60,3),1.2,colors.black),
]
def Add_Consolidation(self):
fill=16-self.table_count
self.elements.append(Spacer(1, fill*15))
self.Consolidation_Table=Table(self.CONSOLIDATION,[9*cm]+[4*cm]+[1*cm]*3+[9*cm]*3,[.3*cm]+[.3*cm]*4)
self.Consolidation_Table.setStyle(TableStyle(self.Consolidation_Style))
self.elements.append(Spacer(1, 10))
self.elements.append(self.Consolidation_Table)
def AddPage(self):
self.Score_Table=Table(self.Score_Data,[self.cW1*cm]+8*[self.cW*cm], [self.rH1*cm]+[self.rH2*cm]+14*[self.rH*cm])
#self.Attendance_Table=Table(self.Attendance_Data,[self.cW*2.2*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Attendance_Table=Table(self.Attendance_Data,[self.cW1*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Score_Table.setStyle(TableStyle(self.Score_T_Style))
self.Attendance_Table.setStyle(TableStyle(self.Attendance_T_Style))
self.elements.append(self.Score_Table)
self.elements.append(Spacer(1, 15))
self.elements.append(self.Attendance_Table)
self.elements.append(PageBreak())
def AddPage(self):
#self.Score_Table=Table(self.Score_Data,[.3*inch]+[1*inch]+8*[0.6*inch], [.8*inch]+[.6*inch]+14*[0.35*inch])
self.Score_Table=Table(self.Score_Data,[.5*inch]+[(self.cW1*cm)-.5*inch]+8*[self.cW*cm], [self.rH1*cm]+[self.rH2*cm]+14*[self.rH*cm])
self.Attendance_Table=Table(self.Attendance_Data,[self.cW*2.2*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Score_Table.setStyle(TableStyle(self.Score_T_Style))
self.Attendance_Table.setStyle(TableStyle(self.Attendance_T_Style))
self.elements.append(self.Score_Table)
self.elements.append(Spacer(1, 18))
self.elements.append(self.Attendance_Table)
self.elements.append(PageBreak())
def AddPage(self):
#self.Score_Table=Table(self.Score_Data,[.3*inch]+[1*inch]+8*[0.6*inch], [.8*inch]+[.6*inch]+14*[0.35*inch])
self.Score_Table=Table(self.Score_Data,[.3*inch]+[(self.cW1*cm)-.3*inch]+8*[self.cW*cm], [self.rH1*cm]+[self.rH2*cm]+14*[self.rH*cm])
self.Attendance_Table=Table(self.Attendance_Data,[self.cW*2.2*cm]+4*[self.cW*2*cm],5*[self.rH*cm])
self.Score_Table.setStyle(TableStyle(self.Score_T_Style))
self.Attendance_Table.setStyle(TableStyle(self.Attendance_T_Style))
self.elements.append(self.Score_Table)
self.elements.append(Spacer(1, 15))
self.elements.append(self.Attendance_Table)
self.elements.append(PageBreak())
def add_info(self):
ptext = '<b><font size=14>Report Info</font></b>'
self.Story.append(Paragraph(ptext, self.styles['BodyText']))
self.Story.append(Spacer(1, 0.1*inch))
data = [
['Request Name', self.request['custom_name']],
['Request Id', str(self.request['_id'])],
['Email', self.request['email']],
['Generated on', self.time_str()],
['Download Link', '<a href="http://{0}/query/#!/status/{1}">{0}/query/#!/status/{1}</a>'.format(
self.download_server, self.request['_id'])]
]
data = [[i[0], pg(i[1], 1)] for i in data]
t = Table(data)
t.setStyle(TableStyle([
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black)
]))
self.Story.append(t)
# full request timeline / other processing info
def _table(self, node):
length = 0
colwidths = None
rowheights = None
data = []
for tr in _child_get(node,'tr'):
data2 = []
for td in _child_get(tr, 'td'):
flow = []
for n in td.childNodes:
if n.nodeType==node.ELEMENT_NODE:
flow.append( self._flowable(n) )
if not len(flow):
flow = self._textual(td)
data2.append( flow )
if len(data2)>length:
length=len(data2)
for ab in data:
while len(ab)<length:
ab.append('')
while len(data2)<length:
data2.append('')
data.append( data2 )
if node.hasAttribute('colWidths'):
assert length == len(node.getAttribute('colWidths').split(','))
colwidths = [utils.unit_get(f.strip()) for f in node.getAttribute('colWidths').split(',')]
if node.hasAttribute('rowHeights'):
rowheights = [utils.unit_get(f.strip()) for f in node.getAttribute('rowHeights').split(',')]
table = platypus.Table(data = data, colWidths=colwidths, rowHeights=rowheights, **(utils.attr_get(node, ['splitByRow'] ,{'repeatRows':'int','repeatCols':'int'})))
if node.hasAttribute('style'):
table.setStyle(self.styles.table_styles[node.getAttribute('style')])
return table
def rpt():
story = []
#??????????reportlab-userguide.pdf?chapter 6 Paragraph
if READ_TYPE == 1: #?????????
rpt_title = '<para autoLeading="off" fontSize=10.5 align=center>'+Read.news_title+'<br/></para>'
story.append(Paragraph(rpt_title, styleH))
table_list=[]
temp=[]
temp.append(Read.news_author)
temp.append(Read.news_time)
table_list.append(temp)
first_table = Table(table_list,colWidths=[225,225])
first_table.setStyle(TableStyle([
('FONTNAME', (0, 0), (1, 0), 'msyhbd'),
('ALIGN', (1, 0), (1, 0), 'RIGHT'), # ???
('ALIGN', (0, 0), (0, 0), 'LEFT'),
('FONTSIZE', (1, 2), (-1, -1), 10.5), # ????
('TEXTCOLOR', (0, 0), (1, 0), colors.standardfl),
]))
story.append(first_table)
news_content_list=Read.news_content.splitlines()
for i in range(len(news_content_list)):
text = ''
text += '<para autoLeading="off" fontSize=10.5 ><font face="msyh" >'
text+=news_content_list[i]
text +='</font></para>'
story.append(Paragraph(text, normalStyle))
if READ_TYPE==2: #??word?????????
doc = docx.Document('test1.docx')
length = len(doc.paragraphs)
rpt_title = '<para autoLeading="off" fontSize=10.5 align=center>' + doc.paragraphs[0].text + '<br/></para>'
story.append(Paragraph(rpt_title, styleH))
rpt_title = '<para autoLeading="off" fontSize=10.5 align=right color=rgb(84,141,212)>' + doc.paragraphs[1].text + '<br/></para>'
story.append(Paragraph(rpt_title, styleH))
for i in range(2,length):
text = ''
if doc.paragraphs[i].style.name=='Heading 3' or doc.paragraphs[i].style.name=='Heading 2'or doc.paragraphs[i].style.name=='Heading 1':
text+='<para autoLeading="off" fontSize=10.5 ><font face="msyhbd" >'
else :
text += '<para autoLeading="off" fontSize=10.5 ><font face="msyh" >'
text+=doc.paragraphs[i].text
text +='</font></para>'
story.append(Paragraph(text, normalStyle))
#?????????reportlab-userguide.pdf?chapter 7 Table
table.parse_docx('test1.docx')
component_data = table.component_data
component_table = Table(component_data)
component_table.setStyle(table_style.table_style)
story.append(component_table)
doc = SimpleDocTemplate('D:/HX/reportlab/bug1.pdf')
doc.build(story)
def detalle(self,pdf,y,orden):
encabezados = ('Item', 'Cantidad', u'Descripción','Precio','Total')
p = ParagraphStyle('parrafos')
p.alignment = TA_JUSTIFY
p.fontSize = 9
p.fontName="Times-Roman"
detalles = []
cont = 0
for detalle in DetalleOrdenServicios.objects.filter(orden=orden):
try:
descripcion = detalle.detalle_cotizacion.detalle_requerimiento.producto.descripcion
if len(descripcion)>58:
cont = cont + 1
detalles.append((detalle.nro_detalle, detalle.cantidad, Paragraph(descripcion,p), detalle.precio,detalle.valor))
except:
descripcion = detalle.producto.descripcion
if len(descripcion)>58:
cont = cont + 1
detalles.append((detalle.nro_detalle, detalle.cantidad, Paragraph(descripcion,p), detalle.precio,detalle.valor))
#detalles = [(detalle.nro_detalle, detalle.cantidad, Paragraph(detalle.servicio.descripcion+'-'+detalle.descripcion,p), detalle.precio,detalle.valor) for detalle in DetalleOrdenServicios.objects.filter(orden=orden)]
adicionales = [('','','','','')]*(15-cont-len(detalles))
detalle_orden = Table([encabezados] + detalles + adicionales,colWidths=[0.8 * cm, 1.9 * cm, 11.3* cm, 2 * cm, 2.5 * cm])
detalle_orden.setStyle(TableStyle(
[
('ALIGN',(0,0),(4,0),'CENTER'),
('GRID', (0, 0), (-1, -1), 1, colors.black),
#('LINEBELOW', (0,1), (5,-1), 0, colors.black),
('FONTSIZE', (0, 0), (-1, -1), 8),
('ALIGN',(4,1),(-1,-1),'RIGHT'),
]
))
detalle_orden.wrapOn(pdf, 800, 600)
detalle_orden.drawOn(pdf, 40,y+75)
#Letras
total_letras = [("SON: "+ orden.total_letras,'')]
tabla_total_letras = Table(total_letras,colWidths=[16 * cm, 2.5 * cm])
tabla_total_letras.setStyle(TableStyle(
[
('GRID', (0, 0), (1, 0), 1, colors.black),
('FONTSIZE', (0, 0), (-1, -1), 8),
]
))
tabla_total_letras.wrapOn(pdf, 800, 600)
tabla_total_letras.drawOn(pdf, 40,y+55)
def afectacion_presupuesta(self,pdf):
y=320
pdf.drawString(40, y-90, u"HOJA DE AFECTACIÓN PRESUPUESTAL:")
p = ParagraphStyle('parrafos')
p.alignment = TA_JUSTIFY
p.fontSize = 8
p.fontName="Times-Roman"
lista = ListFlowable([
Paragraph("""Consignar el número de la presente Orden de Compra en su Guía de Remisión y Factura.
Facturar a nombre de """ + smart_str(EMPRESA.razon_social),p),
Paragraph("El " + smart_str(EMPRESA.razon_social) + """, se reserva el derecho de devolver
la mercaderia, sino se ajusta a las especificaciones requeridas, asimismo de anular la presente
Orden de Compra.""",p),
Paragraph("""El pago de toda factura se hará de acuerdo a las condiciones establecidas.""",p)
],bulletType='1'
)
p1=Paragraph("RECIBIDO POR: ",p)
pdf.drawString(330, y-150,"FIRMA: ")
pdf.line(370, y-150, 560, y-150)
pdf.drawString(330, y-170,"NOMBRE: ")
pdf.line(370, y-170, 560, y-170)
pdf.drawString(330, y-190,"DNI: ")
pdf.line(370, y-190, 560, y-190)
pdf.setFont("Times-Roman", 6)
pdf.drawString(525, y-127,"FECHA")
afectacion = [[(Paragraph("IMPORTANTE:",p), lista),"RECIBIDO POR:"]]
tabla_afectacion = Table(afectacion,colWidths=[10 * cm, 8.50 * cm])
tabla_afectacion.setStyle(TableStyle(
[
('GRID', (0, 0), (1, 0), 1, colors.black),
('VALIGN',(1,0),(1,0),'TOP'),
('FONTSIZE', (0, 0), (-1, -1), 8),
]
))
tabla_afectacion.wrapOn(pdf, 800, 600)
tabla_afectacion.drawOn(pdf, 40,y-200)
fecha = [[' ',' ',' ']]
tabla_fecha = Table(fecha,colWidths=[0.6 * cm, 0.6 * cm, 0.6 * cm], rowHeights=0.6 * cm)
tabla_fecha.setStyle(TableStyle(
[
('GRID', (0, 0), (-1, -1), 1, colors.black),
('FONTSIZE', (0, 0), (-1, -1), 5),
]
))
tabla_fecha.wrapOn(pdf, 800, 600)
tabla_fecha.drawOn(pdf, 510,y-120)
def tabla_firmas(self):
requerimiento = self.requerimiento
solicitante = requerimiento.solicitante
puesto_solicitante = solicitante.puesto
p = ParagraphStyle('parrafos',
alignment=TA_CENTER,
fontSize=8,
fontName="Times-Roman")
encabezados = [(u'Recepción', '', '', '', '', '')]
oficina = requerimiento.oficina
jefatura_logistica = self.obtener_puesto(LOGISTICA, requerimiento)
jefe_logistica = jefatura_logistica.trabajador
firma_solicitante = self.obtener_firma(solicitante.firma)
firma_jefe_oficina_logistica = self.obtener_firma(jefe_logistica.firma)
solicitante = requerimiento.solicitante.nombre_completo()
cuerpo = [('', '', '', '', '', '')]
if requerimiento.aprobacionrequerimiento.nivel.descripcion == "USUARIO" and requerimiento.aprobacionrequerimiento.estado:
cuerpo = [('', firma_solicitante, '', '', '', '')]
elif requerimiento.aprobacionrequerimiento.nivel.descripcion == "LOGISTICA" and requerimiento.aprobacionrequerimiento.estado:
cuerpo = [(firma_jefe_oficina_logistica, firma_solicitante, '', '','', '')]
try:
fecha_recepcion = requerimiento.fecha_recepcion.strftime('%d/%m/%Y')
except:
fecha_recepcion = ''
pie = [(Paragraph('Fecha: ' + fecha_recepcion + "<br/>" + jefe_logistica.nombre_completo(), p),
Paragraph("Solicitado por: <br/>" + solicitante, p),
'',
'',
'',
'')]
tabla_firmas = Table(encabezados + cuerpo + pie,
colWidths=[3.3 * cm, 3.3 * cm, 3.3 * cm, 3.3 * cm, 3.4 * cm, 3.4 * cm],
rowHeights=[0.5 * cm, 2 * cm, 1.8 * cm])
tabla_firmas.setStyle(TableStyle(
[
('GRID', (0, 0), (5, 2), 1, colors.black),
('FONTSIZE', (0, 0), (-1, -1), 8),
('ALIGN', (0, 0), (-1, -1), 'LEFT'),
('ALIGN', (0, 1), (5, 1), 'CENTER'),
('ALIGN', (0, 2), (5, 2), 'CENTER'),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
]
))
return tabla_firmas
def call_report(request):
event_assignment = get_object_or_404(EventAssignment,
pk=request.session['assignment_id'])
event = event_assignment.event
user = request.user
contact_history = Contact.objects.filter(
event=event, author=user
).order_by('-date_of_contact')
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'inline; filename="call_report.pdf"'
buffr = BytesIO()
styles = getSampleStyleSheet()
cell_style = styles['BodyText']
cell_style.alignment = TA_LEFT
report_details = []
title = Paragraph('Call Note Report', styles['title'])
report_details.append(title)
conf_details_text = event.number + ': ' + event.title + ' (' \
+ user.username+ ')'
report_details.append(Paragraph(conf_details_text, styles['h2']))
report = SimpleDocTemplate(buffr, pagesize=letter,
leftMargin=inch/2, rightMargin = inch/2)
data = []
for contact in contact_history:
person = contact.person.name
if contact.person.title:
person = person + '<br/>' + contact.person.title
if contact.person.company:
person = person + '<br/>' + contact.person.company
date = Paragraph(str(contact.date_of_contact.date()), cell_style)
person = Paragraph(person, cell_style)
notes = Paragraph(contact.notes[:3500], cell_style)
data.append([date, person, notes])
table = Table(data, [inch, 3 * inch, 4.5 * inch])
table.setStyle(TableStyle([('VALIGN', (0,0), (-1, -1), 'TOP')]))
report_details.append(table)
data = []
# if len(data) > 0:
# call_detail_table = Table(data, [inch, 2 * inch, 4.5 * inch])
# call_detail_table.setStyle(TableStyle([('VALIGN', (0,0),
# (-1, -1), 'TOP')]))
# report_details.append(call_detail_table)
report.build(report_details)
pdf = buffr.getvalue()
buffr.close()
response.write(pdf)
return response
def SetTable_Style(self):
#Starts Score Table
self.Score_T_Style=[('BOX',(0,0),(-1,-1),1.7,colors.black),
('GRID',(0,0),(-1,-1),1,colors.black),#
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('FONTname',(0,0),(-1,-1),'Helvetica-Bold'),
('SPAN',(0,0),(-1,0)), # SCHOOL
('ALIGN',(0,0),(-1,0),'CENTER'),
('SPAN',(0,1),(-1,1)), # PERFORMANCE CARD OF
('SPAN',(0,2),(4,2)), #ADM NOO
('SPAN',(5,2),(-1,2)), # YEAR
('ALIGN',(2,0),(3,-1),'LEFT'),
('SPAN',(0,3),(4,3)), # ROLL NO
('SPAN',(5,3),(-1,3)), #CLASS
('SPAN',(0,4),(0,5)), #SUBJECT LABEL
('SPAN',(1,4),(4,4)), #TERM1
('ALIGN',(1,4),(4,4),'CENTER'),
('SPAN',(5,4),(-1,4)), #TERM2
('ALIGN',(5,4),(-1,4),'CENTER'),
('BOX',(1,4),(4,-1),1.5,colors.black),
('BOX',(5,4),(-1,-1),1.5,colors.black),
('ALIGN',(2,5),(-1,5),'CENTER'),
('ALIGN',(1,6),(-1,-1),'CENTER')
]
#End of Score Table
#Starts Attendance Tabke style
self.Attendance_T_Style=[('GRID',(0,0),(-1,-1),1,colors.black),
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('SPAN',(0,0),(0,1)),
('SPAN',(1,2),(2,2)),
('SPAN',(3,2),(4,2)),
('SPAN',(1,3),(2,3)),
('SPAN',(3,3),(4,3)),
('SPAN',(1,4),(2,4)),
('SPAN',(3,4),(4,4)),
('BOX',(0,0),(-1,-1),2,colors.black)]
#end of Attendance Table Style