On 30 Dec 2013, at 7:31 AM, Anthony <abasta...@gmail.com> wrote:
> Sorry, a couple mistakes in the code. This should do it:

There's a pyrtf example in the book 
<http://web2py.com/books/default/chapter/29/10/services?search=pyrtf#PyRTF> 
that uses a helper (dumps) and apparently returns a string. I wonder whether 
the example shouldn't be updated to take advantage of response.stream; we're 
short of response.stream examples anyway.

> 
> def generate_doc():
>     from gluon.contrib.pyrtf import *
>     import cStringIO
>     
>     doc     = Document()
>     ss      = doc.StyleSheet
>     section = Section()
>     doc.Sections.append( section )
>     
>     p = Paragraph( ss.ParagraphStyles.Heading1 )
>     p.append( 'Certified Staff Evaluation' )
>     section.append( p )
> 
>     s = cStringIO.StringIO()
>     Renderer().Write(doc, s)
>     s.seek(0)
>     return response.stream(s, attachment= True, filename='yourdocument.rtf')
> 
> Anthony
> 
> On Monday, December 30, 2013 7:52:07 AM UTC-5, Diego Tostes wrote:
> thanks anthony,
> 
> but did not works... the result was a file with no name with "None" printed 
> at the first page....
> 
> 
> 2013/12/29 Anthony
> You are attempting to return a pyrtf.Document object, but instead you must 
> stream a file or file-like object. You have to render the document to a 
> file-like object and use response.stream():
> 
> def generate_doc():
>     from gluon.contrib.pyrtf import *
>     import cStringIO
>     
>     doc     = Document()
>     ss      = doc.StyleSheet
>     section = Section()
>     doc.Sections.append( section )
>     
>     p = Paragraph( ss.ParagraphStyles.Heading1 )
>     p.append( 'Certified Staff Evaluation' )
>     section.append( p )
>  
>     s = cStringIO.StringIO()
>     Renderer().Write(doc, s)
>     s.seek(0)
>     return response.stream(s, attachment= True, filename='yourdocument.rtf')
> 
> Specifying the filename with the ".rtf" extension ensures the content-type 
> header will be set properly automatically.
> 
> Anthony
> 
> On Saturday, December 28, 2013 4:20:34 PM UTC-5, Diego Tostes wrote:
> here is my code:
> 
> http://pastebin.com/qh5AV8Xh
> 
> but the download don't start when i access this controler.
> 
> 
> 
> 
> 
> 
> 2013/12/28 Diego Tostes <tostes...@gmail.com>
> i am using the pyrtf, but i dont know how create the file and download 
> without save the file on the server.
> 
> any idea?
> 
> 
> 2013/12/28 Anthony <abas...@gmail.com>
> There's also python-docx.
> 
> 
> On Saturday, December 28, 2013 10:35:33 AM UTC-5, Diego Tostes wrote:
> done using 
> PyRTF
> 
> 
> 
> thanks
> 
> 
> 
> 2013/12/28 Diego Tostes <tostes...@gmail.com>
> 
> Hi,
> 
> Is it possible create doc files (word or openoffice) using templates 
> rendering?
> 
> Rgds,
> 
> Diego
> 
> 
> -- 
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to