Rectangle 27 0

Rails, Prawn PDF show up in browser & etc?


That said, for anything but a trivial PDF you will probably want to generate it outside the controller somewhere.

Note
Rectangle 27 0

Rails, Prawn PDF show up in browser & etc?


Hi, for me its not going to save in that folder. but it goes there to find that is that pdf is there or not? any solution to store pdf in public folder?

How can I force prawn to generate the file in the app/report (or any other selected) folder?

How can I make it to save and show up in the browser window?

How can I make the action to generate the file in the browser window and don't save it?

in the send_data you should add the option :disposition => 'inline'

Note
Rectangle 27 0

Rails, Prawn PDF show up in browser & etc?


:disposition => 'inline' will force the browser ( if it can ) to display your PDF inside the current browser window

Benoit Garret's answer is very good, but I should note on the second example:

How can I make the action to generate the file in the browser window and don't save it?

Note
Rectangle 27 0

Rails, Prawn PDF show up in browser & etc?


:disposition => 'inline'
def index
  pdf = Prawn::Document.new
  pdf.text 'Hello World'
  send_data pdf.render, filename: 'x.pdf', type: 'application/pdf', disposition: 'inline'
end

Answering Question 3: "How can I make it to save and show up in the browser window?"

disposition: 'inline' will force the browser ( if it can ) to display your PDF inside the current browser window

Note
Rectangle 27 0

Rails, Prawn PDF show up in browser & etc?


def index
  pdf = Prawn::Document.new
  pdf.text "Hello World"
  filename = File.join(Rails.root, "app/report", "x.pdf")
  pdf.render_file filename
  send_file filename, :filename => "x.pdf", :type => "application/pdf"
end
def index
  pdf = Prawn::Document.new
  pdf.text "Hello World"
  send_data pdf.render, :filename => "x.pdf", :type => "application/pdf"
end

Hi, for me its not going to save in that folder. but it goes there to find that is that pdf is there or not? any solution to store pdf in public folder?

How can I force prawn to generate the file in the app/report (or any other selected) folder?

How can I make it to save and show up in the browser window?

How can I make the action to generate the file in the browser window and don't save it?

in the send_data you should add the option :disposition => 'inline'

Note
Rectangle 27 0

Rails, Prawn PDF show up in browser & etc?


def index
  pdf = Prawn::Document.new
  pdf.text "Hello World"
  send_data pdf.render, :filename => "x.pdf", :type => "application/pdf"
 end

That said, for anything but a trivial PDF you will probably want to generate it outside the controller somewhere.

Note