2011-05-16 45 views

回答

2

这很容易与PDFKit

@your_object = YourObject.find(params[:id]) 
respond_to do |format| 
    format.pdf do 
    #html = render_to_string(:action => "show.html.haml", :layout => "pdf.html.haml") 
    html = @your_object.your_html_field 
    content = PDFKit.new(html) 
    send_data(content.to_pdf, :filename => "content.pdf", :type => 'application/pdf', :disposition => 'inline') 
    end 
end 

它在后台使用wkhtmltopdf,它是很容易install了。它有很多选项可以定制一代pdf。

瑞安贝茨有一个screencast就可以了。