How to save rails generated pages to a file on the server

My show view of a data form is finished and now I want to give a
possibility to download this view as a pdf file.

I would like to use HTMLDOC to convert the html text to pdf. My idea:
save the html text to a temporary folder and run HTMLDOC.

But how can I save the html text to a file?

On Mar 19, 2010, at 11:43 AM, Fritz T. wrote:

My show view of a data form is finished and now I want to give a
possibility to download this view as a pdf file.

I would like to use HTMLDOC to convert the html text to pdf. My idea:
save the html text to a temporary folder and run HTMLDOC.

But how can I save the html text to a file?

render_to_string

http://api.rubyonrails.org/classes/ActionController/Base.html#M000659

That puts it into a local variable anyway… if you can then pass that
to htmldoc you’re on your way. Not sure how this might affect any
paths to CSS/images for HTMLDOC though.

Philip H. wrote:

render_to_string

http://api.rubyonrails.org/classes/ActionController/Base.html#M000659

That puts it into a local variable anyway… if you can then pass that
to htmldoc you’re on your way. Not sure how this might affect any
paths to CSS/images for HTMLDOC though.

Thanks. CSS is “no problem” with HTMLDOC - it doesn’t support it :wink:

Maybe, I need to find some alternative for HTMLDOC. My problem is, that
I have a table with variable number of columns.

Maybe, I need to find some alternative for HTMLDOC. My problem is,
that
I have a table with variable number of columns.

Prawn. http://railscasts.com/episodes/153-pdfs-with-prawn

You might want to check out:

http://code.google.com/p/wkhtmltopdf/
http://www.princexml.com/

wkhtmltopdf is free. prince will cost you. prince has better css
print-related implementation coverage at this time, but wkhtmltopdf
can be a very good alternative depending on the needs of your project.

Jeff

Prawn seems to need a fixed number of columns in tables, so I’ll take a
look on wkhtmltopdf.

Since I started using tools (like prince/wkhtmltopdf) to generate pdfs
from html/css for web app projects that need to gen pdfs, I’ve never
gone back to using low-level pdf-gen’ing libs/tools (like prawn).
Just requires so much less work.

By the way, you may also want to look into using
http://www.accesspdf.com/pdftk/
in combination with wkhtmltopdf(/prince) in case you need to do any
post-processing of your gen’d pdfs (adding additional watermarks,
splitting out pdf pages, combining pdfs, …).

Jeff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs