You can try phantomJS, it's very easy to convert html to PDF file.

2012/5/24 Matt <[email protected]>

> My apologies; I was using tg2 2.1.1, and the code seems to have changed to
> pass a dictionary in 2.1.4.
>
> For those finding this thread after me via google, the solution I ended up
> going with is using xhtml.wsgi.PisaMiddleware (sample usage in
> https://github.com/chrisglass/xhtml2pdf/tree/master/demo/wsgi )
>
> Thanks for your response, Alessandro
>
>
> On Wed, May 23, 2012 at 4:11 PM, Alessandro Molina <
> [email protected]> wrote:
>
>> Actually after_render hook permits to modify the rendered page.
>>
>> It gets as parameter a dictionary where the key "response" is the
>> response getting out from that request.
>> Replacing the content of that key replaces the response sent by
>> TurboGears.
>>
>> On Tue, May 22, 2012 at 8:56 PM, Matthew Boehm <[email protected]>
>> wrote:
>> > I am trying to implement a PDF converter as well, but have run into some
>> > problems:
>> >
>> > * after_render hooked functions only receive a literal with the rendered
>> > result. Modifying this result/returning the modified version in the
>> hooked
>> > function does not change what is written to the response object.
>> > * If you try writing directly to the response object, sometime after
>> your
>> > function returns, the entire original response is written to the
>> response
>> > object.
>> >
>> > Is there a way to modify the response's content and headers in a
>> function
>> > hooked to after_render?
>> >
>> > On Monday, September 19, 2011 10:38:32 AM UTC-4, Alessandro Molina
>> wrote:
>> >>
>> >> you can use
>> >>
>> Decoration.get_decoration(controller_method).register_hook('after_render',
>> >> callable)
>> >> and callable will be execute after rendering the template with the
>> >> rendering result as parameter.
>> >>
>> >> On Mon, Sep 19, 2011 at 3:32 PM, León Domingo <[email protected]>
>> >> wrote:
>> >> > Hi Alessandro,
>> >> > And how would it be this way? I don't know exactly how "after_render"
>> >> > has to be used. As far as I know, you define a function with a
>> >> > "response" parameter and then a decorator "after_render" passing that
>> >> > function in.
>> >> >
>> >> > def _after_render(r):
>> >> >  # something to be done
>> >> >  r.content_type = 'application/pdf'
>> >> >  r.body = to_pdf(r.body)
>> >> >
>> >> > @expose('foo.html')
>> >> > @after_render(_after_render)
>> >> > def foo(self, *args, **kwargs):
>> >> >   return dict(....)
>> >> >
>> >> > is it correct? I was trying this way but...can I modify "response"
>> >> > inside "_after_render"? I thought it was not possible...
>> >> >
>> >> > Thanks
>> >> >
>> >> > León
>> >> >
>> >> > On 19 sep, 15:13, Alessandro Molina <[email protected]>
>> >> > wrote:
>> >> >> Uhm, I would suggest you to setup a after_render hook and decide if
>> >> >> the render result must be converted to a PDF or not.
>> >> >> In the case it doesn't have to be converted you can leave it go as
>> >> >> HTML, otherwise you can call wkhtmltopdf
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> On Sun, Sep 18, 2011 at 9:54 AM, León Domingo <
>> [email protected]>
>> >> >> wrote:
>> >> >> > Hi,
>> >> >> > I've created a little function that makes use of wkhtmltopdf
>> (http://
>> >> >> > code.google.com/p/wkhtmltopdf/) to get PDF content from HTML
>> content.
>> >> >>
>> >> >> > I would like to use some controllers to get a PDF version of the
>> HTML
>> >> >> > content defined in the corresponding template.
>> >> >>
>> >> >> >   @expose('foo.html')
>> >> >> >   def foo(self, *args, **kwargs):
>> >> >> >       return dict(....)
>> >> >>
>> >> >> > I've been making some experiments with a middleware class.
>> >> >>
>> >> >> >   response.content_type = 'application/pdf'
>> >> >> >   response.body = to_pdf(response.body)
>> >> >>
>> >> >> >   return response(environ, start_response)
>> >> >>
>> >> >> > It works but I need something to know if I have to make the
>> >> >> > translation or not
>> >> >>
>> >> >> >   if is_a_suitable_response:
>> >> >> >       response.content_type = 'application/pdf'
>> >> >> >       response.body = to_pdf(response.body)
>> >> >>
>> >> >> >   return response(environ, start_response)
>> >> >>
>> >> >> > and I don't know how I can "mark" the response to do so. In the
>> other
>> >> >> > hand, I don't know if this is the right way to do that.
>> >> >>
>> >> >> > Thanks a lot
>> >> >>
>> >> >> > León
>> >> >>
>> >> >> > --
>> >> >> > 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
>> >> >> > athttp://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.
>> >> >
>> >> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "TurboGears" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/turbogears/-/L9-eC9I7gBkJ.
>> >
>> > 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.
>>
>>
>  --
> 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.
>



-- 
Deng Chao

-- 
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