Is that all your code? I don't see a line like this (from my generate_pdf function):
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 30 Mar, 18:58, Sven Richter <sver...@googlemail.com> wrote: > Great, thank you very much, this got me started. However, its not > working yet. This is the code i have right now: > > 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 > > On Tue, Mar 30, 2010 at 6:56 PM, Paulo Almeida > > > > <igcbioinformat...@gmail.com> wrote: > > I'm using Platypus (part of reportlab) to generate pdfs without > > micromanagement of Canvas elements. reportlab's documentation was very > > helpful to learn how to work with Paragraph, Table, Image, etc. Some code: > > # views.py > > @login_required > > def view_pdf(request, experiment_id): > > experiment = > > get_object_or_404(Experiment.objects.filter(pk=experiment_id)) > > response = HttpResponse(mimetype='application/pdf') > > filename = slugify(experiment.title) + '.pdf' > > response['Content-Disposition'] = 'filename=' + filename > > generate_pdf([experiment], response) > > return response > > # functions.py > > def generate_pdf(experiments, output): > > doc = SimpleDocTemplate(output, pagesize=A4) > > Document = [] > > for experiment in experiments: > > Document.extend(pdf_elements(experiment)) > > doc.build(Document) > > pdf_elements is a function that adds bits and pieces... This is just an > > excerpt: > > def pdf_elements(experiment): > > styles = getSampleStyleSheet() > > Document = [Paragraph(escape(experiment.title), styles["Title"])] > > Document.append(Spacer(1,50)) > > date = unicode(experiment.date.strftime("%B %d, %Y")) > > Document.append(Paragraph("Acquired on " + date, styles["Normal"])) > > date_now = unicode(datetime.now().strftime("%B %d, %Y")) > > Document.append(Paragraph("PDF created on " + date_now, > > styles["Normal"])) > > Document.append(Spacer(1,10)) > > return Document > > Read the Platypus documentation for many more elements and options. > > These are my reportlab imports: > > from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, > > TableStyle > > from reportlab.platypus import KeepTogether > > from reportlab.platypus import Table as Platypus_Table > > from reportlab.platypus import Image as Platypus_Image > > from reportlab.lib import colors > > from reportlab.lib.pagesizes import A4 > > from reportlab.lib.styles import getSampleStyleSheet > > - Paulo > > > On Tue, Mar 30, 2010 at 5:08 PM, Sven Richter <sver...@googlemail.com> > > wrote: > > >> Hi everybody, > > >> 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-us...@googlegroups.com. > >> To unsubscribe from this group, send email to > >> django-users+unsubscr...@googlegroups.com. > >> For more options, visit this group at > >>http://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.