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]<turbogears%[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.

Reply via email to