Rails, Prawn - PDF show up in browser & etc

前端 未结 3 967
囚心锁ツ
囚心锁ツ 2020-12-07 22:11

I\'m trying to understand the Prawn pdf gem.

I was able to make it generate a pdf. Every gem in the gemfile included:

gem \'mysql\', \'~> 2.8.1\'
         


        
3条回答
  •  情书的邮戳
    2020-12-07 22:38

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

    def index
      pdf = Prawn::Document.new
      pdf.text "Hello World"
      pdf.render_file File.join(Rails.root, "app/report", "x.pdf")
    end
    

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

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

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

    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
    

提交回复
热议问题