This is what i have in my program, in 'root.py': def print_list(self): fichero = StringIO.StringIO() informe = CrearPDF(fichero) [...] pdf = fichero.getvalue() fichero.close() pylons.response.headers['Content-Type'] = 'application/pdf' pylons.response.headers['Content-Disposition'] = 'attachment;filename=lista.pdf' return(pdf)
The part that i haven't written is the part where i prepare the code to generate my pdf. I'm using turbogears2. If you need a more detailed explanation of my class 'crearPDF' i can post it too. I hope this is useful to you. 2010/1/19 sam aikins <[email protected]>: > thanks buddy.yup this solution works in turbogears 1.but i am using > turbogears 2.yea but thanks for the help anyway :-) > > On Sat, Jan 16, 2010 at 8:41 PM, Martin Eliasson <[email protected]> > wrote: >> >> I don't know why your code doesent work, but I have done the following in >> TG1 (based on CherryPy) in order to generate pdf on-the-fly and serving it >> to users using ReportLab: >> >> TG1 part: >> >> @expose() >> def label_maker_make(self, file=None, tg_errors=None) >> txtout = label_maker.main(file).getvalue() >> cherrypy.response.headerMap["Content-Type"] = "application/x-pdf" >> cherrypy.response.headerMap['Content-Length'] = len(txtout) >> cherrypy.response.headerMap["Content-Disposition"] = "attachment; >> filename=labels.pdf" >> return txtout >> >> >> >> And in the label_maker module, I start the function gereating the pdf with >> >> buffer = StringIO() >> c = canvas.Canvas(buffer, pagesize=A4) >> >> >> and end it with: >> >> c.showPage() >> c.save() >> return buffer >> >> I hope this helps. >> >> /Martin >> >> >> >> >> 2010/1/13 sam <[email protected]> >>> >>> i am currently trying to dynamically generate a pdf file and serve it >>> to users to download.but the problem is the pdf is generated to the >>> local machine and the document that is served for download is >>> blank.please i really need some help. >>> this is what i am using >>> >>> >>> �...@expose(content_type="application/pdf") >>> def coverpage(self): >>> >>> >>> >>> buff = StringIO.StringIO() >>> >>> >>> p = canvas.Canvas("toby.pdf") >>> >>> >>> p.drawString(100, 100, "Helloworld.") >>> p.showPage() >>> p.save() >>> buff.write(p) >>> pdf =buff.getvalue() >>> buff.close() >>> >>> return( pdf ) >>> >>> this " http://achievewith.us/public/articles/category/turbogears" was >>> my initial guide but it doesn't really help.as i do not know where the >>> method "generate_lettersv2(Applicant.select(), letters_file)" in the >>> code below is coming from >>> >>> >>> >>> pdfdemo.controllers.Root.letters() >>> >>> �...@expose(content_type="application/pdf") >>> def letters(self, **kw): >>> letters_file = StringIO() >>> generate_lettersv2(Applicant.select(), letters_file) >>> pdf = letters_file.getvalue() >>> letters_file.close() >>> return(pdf) >>> >>> i really need this for my project.thanks in advance >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "TurboGears" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/turbogears?hl=en. >>> >>> >>> >> >> >> >> -- >> Martin Eliasson >> +46 (0) 739 97 87 33 >> http://asplunden.org >> >> -- >> You received this message because you are subscribed to the Google Groups >> "TurboGears" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/turbogears?hl=en. >> > > > -- > You received this message because you are subscribed to the Google Groups > "TurboGears" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/turbogears?hl=en. > > -- There's no religion but sex and music -- Sting
-- You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

