[reportlab-users] Force Table to dispaly in one page rather than in next page

Asif Jamadar asif.jamadar at rezayat.net
Sat Jun 25 02:53:52 EDT 2011



Hey andy,

I have another question about tables in reportlab. Currently in my app my table is dynamic, means it uses data from the database. Now my question is if values in database are increased then how should I fit table in one page.

I tested using multiple values from the database so table is continued in next page so how should I force this table to be appeared in a single page?



----------------------------------------------------------------------

Message: 1
Date: Thu, 23 Jun 2011 05:14:03 +0000
From: Asif Jamadar <asif.jamadar at rezayat.net>
Subject: [reportlab-users] Saving the generated report into Django
model
To: "reportlab-users at lists2.reportlab.com"
<reportlab-users at lists2.reportlab.com>
Message-ID:
<CC0CC2862BF94D41A65DC4511A12B49328FCF73C at weaver.REZAYAT.NET>
Content-Type: text/plain; charset="us-ascii"

I found the solution,

def report(request)

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;filename=ANALYSIS_REPORT.pdf'
buffer = StringIO()

doc = SimpleDocTemplate(buffer)

#Create the PDF


doc.build(document, onLaterPages=header_footer)

pdf = buffer.getvalue()

myfile = ContentFile(pdf)

m = Report()

m.file.save('test.pdf', myfile)

response.write(pdf)

return response

Here Report is the model and file is the field of Report model.

Hope it will help someone



-----Original Message-----
From: reportlab-users-bounces at lists2.reportlab.com [mailto:reportlab-users-bounces at lists2.reportlab.com] On Behalf Of reportlab-users-request at lists2.reportlab.com
Sent: Wednesday, June 22, 2011 7:00 PM
To: reportlab-users at lists2.reportlab.com
Subject: reportlab-users Digest, Vol 87, Issue 12

Send reportlab-users mailing list submissions to
reportlab-users at lists2.reportlab.com

To subscribe or unsubscribe via the World Wide Web, visit
http://two.pairlist.net/mailman/listinfo/reportlab-users
or, via email, send a message with subject or body 'help' to
reportlab-users-request at lists2.reportlab.com

You can reach the person managing the list at
reportlab-users-owner at lists2.reportlab.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of reportlab-users digest..."


Today's Topics:

1. how can i save PDF report into django model (Asif Jamadar)
2. Re: how can i save PDF report into django model (Andy Robinson)


----------------------------------------------------------------------

Message: 1
Date: Wed, 22 Jun 2011 05:23:48 +0000
From: Asif Jamadar <asif.jamadar at rezayat.net>
Subject: [reportlab-users] how can i save PDF report into django model
To: "reportlab-users at lists2.reportlab.com"
<reportlab-users at lists2.reportlab.com>
Message-ID:
<CC0CC2862BF94D41A65DC4511A12B49328FCE637 at weaver.REZAYAT.NET>
Content-Type: text/plain; charset="us-ascii"

How can I save the dynamically generated PDF report into separate django model (database) as file.

I created model called 'Reports', in this model I defined a FileField.

In models.py

Class Report(models.Model):

file = models.FileField(upload_to='uploads/documents)'


In views.py

def report(request):

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;filename=ANALYSIS_REPORT.pdf'
buffer = StringIO()
doc = SimpleDocTemplate(response)
...................................................................
....................................................................
doc.build(document)
pdf = buffer.getvalue()

myfile = ContentFile(pdf)
m = Report()
m.file.save('test.pdf', myfile)
return response

But the above code saves the EMPTY report. So any advice on how to save the generated PDF report in django model

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20110622/94e9ca56/attachment.htm>

------------------------------

Message: 2
Date: Wed, 22 Jun 2011 08:50:06 +0100
From: Andy Robinson <andy at reportlab.com>
Subject: Re: [reportlab-users] how can i save PDF report into django
model
To: reportlab-users <reportlab-users at lists2.reportlab.com>
Message-ID: <BANLkTimTnS13n41mJaDGofSgQ5=mVKbx_w at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On 22 June 2011 06:23, Asif Jamadar <asif.jamadar at rezayat.net> wrote:

> ???????? response = HttpResponse(mimetype='application/pdf')

>

> ?? ???????????? ?????????response['Content-Disposition'] =

> 'attachment;filename=ANALYSIS_REPORT.pdf'

>

> ??????????????? ??????? buffer = StringIO()

> ??????????????? ?????? doc = SimpleDocTemplate(response)

> ??????????????? ???? doc.build(document)

> ??????????????? ???? pdf = buffer.getvalue()


It looks from this like you are not actually using the 'buffer' variable. Try
doc.build(document, filename=buffer)

Originally we allowed a filename, but later we generalised it to allow
a file-like object.

- Andy

------------------------------

_______________________________________________
reportlab-users mailing list
reportlab-users at lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users


End of reportlab-users Digest, Vol 87, Issue 12
***********************************************


------------------------------

Message: 2
Date: Thu, 23 Jun 2011 08:17:58 +0100
From: Andy Robinson <andy at reportlab.com>
Subject: Re: [reportlab-users] Saving the generated report into Django
model
To: reportlab-users <reportlab-users at lists2.reportlab.com>
Message-ID: <BANLkTinAWGQGdfQWrVAKfexb1Q16fpB6UQ at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On 23 June 2011 06:14, Asif Jamadar <asif.jamadar at rezayat.net> wrote:

> I found the solution,

> ? ? ? ? ?doc = SimpleDocTemplate(buffer)

Apologies, my memory was failing me (I usually do this through RML) -
this is the right way to do it.

- Andy


------------------------------

_______________________________________________
reportlab-users mailing list
reportlab-users at lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users


End of reportlab-users Digest, Vol 87, Issue 13
***********************************************


More information about the reportlab-users mailing list