i am looking for a way to get BaseDocTemplate from the reportlab
library working, connected with a httpresponse.
I found the documentation for a simple reportlab page, using canvas.
But to me it seems, that i need more options than basic Canvas offers.
Like a page header or footer, tables continuing over pages etc.
I have not found a working example to use httpresponse:
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
in conjunction with:
BaseDocTemplate('basedoc.pdf',showBoundary=1)
So if somebody could provide some working code, or a hint to
repository or an application with some working code, i'd really
appreciate that.
Greetings
Sven
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
def generate_pdf(request):
    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
    styles = getSampleStyleSheet()
    Document = [Paragraph('rd', styles["Title"])]
    Document.append(Spacer(1,50))
    date_now = unicode(datetime.now().strftime("%B %d, %Y"))
    Document.append(Paragraph("PDF created on " + date_now, styles["Normal"]))
    Document.append(Spacer(1,10))
    doc.build(Document)
    return response
But instead of showing the pdf i get the error:
Exception Type:  	IndexError
Exception Value: 	list index out of range
I cannot imagine what may be wrong there? From my point of view it
should work like that?
Greetings
Sven
You can look through my code: http://github.com/nbv4/flightloggin/blob/master/pdf/pdf.py
and an example of some output:
doc = SimpleDocTemplate(response, pagesize=A4)
That's what links the 'response' variable to the output of the
doc.build function. But I don't think that should be what's causing
the IndexError, because you don't assign doc to anything. It should
just complain that doc is not defined. For what it's worth, the pdf
generating part of your code works and generates a pdf (if you include
the 'doc = ...' line above)
- Paulo
> > On Tue, Mar 30, 2010 at 5:08 PM, Sven Richter <sver...@googlemail.com>
But it doesnt generate a pdf like that, it just complains about that IndexError.
Greetings
Sven
Greetings
Sven
Hm, its indeed hard. I really dont know what that Error will tell me.
My Application is a very basic one. Up to now i do everything in the
admin interface. The only url defined is the one to view the pdf file:
urls.py:
urlpatterns = patterns('',
    # Example:
    # (r'^eiwomisa/', include('eiwomisa.foo.urls')),
    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
    (r'^project/task/', include('project.task.urls')),
    (r'^office/job/', include('office.job.urls')),
)
offic/job/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('office.job.views',
    (r'/offer/generate/pdf/$', 'generate_pdf', '',
'office_job_generate_offer_pdf'),
)
and here is my views.py:
def generate_pdf(request):
    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
doc = BaseDocTemplate(filename=response,pagesize=A4)
    styles = getSampleStyleSheet()
    Document = [Paragraph('rd', styles["Title"])]
    Document.append(Spacer(1,50))
    date_now = unicode(datetime.now().strftime("%B %d, %Y"))
    Document.append(Paragraph("PDF created on " + date_now, styles["Normal"]))
    Document.append(Spacer(1,10))
    doc.build(Document)
I have tried the same "setup" with the canvas.Canvas example from the
django documentation, and it worked. All i changed here is from canvas
to document.
Greetings
Sven
Greetings
Sven
def generate_pdf(request):
    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
    template = PageTemplate('normal',  [Frame(2.5*cm, 2.5*cm, 15*cm,
25*cm, id='F1')])
    doc = BaseDocTemplate(filename=response,pagesize=A4,pageTemplates=template)
styles = getSampleStyleSheet()
    Document = [Paragraph('rd', styles["Title"])]
    Document.append(Spacer(1,50))
doc.build(Document)
return response
Thanks all for the help!
Sven