The problem I have is that the table is very long by the data of the BD, those that are passed on the sheet are no longer displayed. What I would like you to help me is that the cells that are left over go to a new PDF page as well as your header. I await your help ... thanks
class ReportEntriesPdf (View):
def cabecera(self,pdf):
archivo_imagen='static/build/images/descarga.png'
pdf.drawImage(archivo_imagen, 30, 700, 110, 90,
preserveAspectRatio=True)
pdf.setFont("Helvetica", 15)
pdf.drawString(180, 760, u"PARQUE RECREACIONAL LOS PINOS")
pdf.setFont("Helvetica", 12)
pdf.drawString(250, 740, u"REPORTE DEENTRADAS VENDIDAS")
def get(self, request, *args, **kwargs):
response = HttpResponse(content_type='application/pdf')
#response['Content-Disposition'] ='attachment;
filename=reportes_reservas.pdf'
buffer = BytesIO()
pdf = canvas.Canvas(buffer)
self.cabecera(pdf)
y = 0
self.tabla(pdf, y)
pdf.showPage()
pdf.save()
pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response
def tabla(self,pdf,y):
encabezados = ('#', 'Entrada', 'fecha', 'Cantidad', 'Total',)
detalles = [(p.id_ventaentrada, p.id_tipoentrada, p.fecha, p.cantidad,
p.monto_total) for p in Venta_Entrada.objects.all()]
detalle_orden = Table([encabezados] + detalles, colWidths=[3 * cm],
rowHeights=0.5 * cm)
detalle_orden.setStyle(TableStyle(
[
('ALIGN',(0,0),(3,0),'CENTER'),
('GRID', (0, 0), (-1, -1), 1, colors.black),
('FONTSIZE', (0, 0), (-1, -1), 10),
('BACKGROUND', (0, 0), (-1, 0), colors.dodgerblue),
('ALIGN',(0,0),(-1,-1),'CENTER'),
]
))
detalle_orden.wrapOn(pdf, 800, 600)
detalle_orden.drawOn(pdf,80 , y - 90)