Search code examples
ruby-on-railspdfprawnto

How to change orientation vertical to horizontal in PDF with Prawnto_2 Rails 4


I use prawnto_2 gem for generate PDF file in Rails 4. In my controller, I only send params for render in my PDF file.

My gemfile have:

#some gems
gem "prawnto_2", :require => "prawnto"

So, in my views folder I have a file with extension .pdf.prawn

An example of my code I use is:

class PdfFilesController < ApplicationController
def user_car_pdf
    @users = User.all
    @car = User.find(params[:id]).car
end

#In user_car_pdf.pdf.prawn

text "User's Car - #{@car.id.to_s.rjust(5, '0')}", :align => :center
move_down 3

@users.each do |data|
  text "#{data.name}# / #{data.email}"
  text "#{data.description}"
end

But, I have a enormous table with much information. So, the vertical orientation is not a option, I need change the orientation.

How I can do that? I have researched and can not find the solution.

Thanks in advance.


Solution

  • :page_layout => :landscape according to the prawnto_2 gem documentation
    
    class PdfFilesController < ApplicationController
      prawnto :prawn => { :page_size => 'A4', :page_layout => :landscape }
    end