view to pdf with pdf::writer

Hello,

I would like to send a view to a pdf file.
To do that I have choosen the tool "pdf::writer", I have tested it and
I found a problem when I do:

             pdf.text render :layout => "my_layout"

it sends the whole html code to the pdf file.

How could I send the result of the html file to the pdf file?

Thanks and let me know if you do not understand it.

Isabel

I've used PDF::Writer to build PDFs and send them back to the
user as a pdf file. Here is what I usually have in my controller
action to do so:

send_data pdf.render, :filename => "filename.pdf", :type => 'application/pdf'

Is that what you need to do?

Franz

> Hello,
>
> I would like to send a view to a pdf file.

I've used PDF::Writer to build PDFs and send them back to the
user as a pdf file. Here is what I usually have in my controller
action to do so:

Thanks for your reply.

send_data pdf.render, :filename => "filename.pdf", :type => 'application/pdf'

I have tried also that and the text into the pdf file is html code.

Is that what you need to do?

This is my code:

    @worker = Worker.find(params[:id])
    pdf = PDF::Writer.new
    pdf.text render :layout => "print"
    send_data pdf.render, :filename => "filename.pdf", :type =>
'application/pdf'

I think the problem is here:
    pdf.text render :layout => "print"
Because the text that I insert in the pdf file is a view...
Is it posible to translate html to pdf?
I have tried with htmldoc, but I have also problems with the charset,
there is no utf-8 option yet..

Franz

Thanks Franz!

Hi Isabel,

For your case, I would suggest that you look at Prawn.
There is a very good screencast at RailsCasts on this:

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

Have fun,
Franz