I want the the table to be displayed in pdf format .
we are using
format.html
format.json{render json: @user}
etc for generating html ,json format
Similarly
so what steps are there if it is possible in rails???
register PDF type for use in respond_to blocks
# config/mime_types.rb
Mime::Type.register "application/pdf", :pdf
in your controller respond to PDF format request
respond_to do |format|
format.html
format.json{render json: @user}
format.pdf do
# ...
# here your PDF generating code
# ...
send_data(your_generated_pdf, filename: 'your_filename.pdf', type: 'application/pdf')
end
end
For generating PDF you can use pdfkit with wkthmltopdf, Prawn and some other. Refer to the respective documentations on their usage.
Starting from Rails 5:
add gem 'responders'
as Rails 5 changelog says: "Remove respond_to/respond_with placeholder methods, this functionality has been extracted to the responders gem"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With