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
评论列表
文章目录