Rails, Prawn - PDF show up in browser & etc

前端 未结 3 959
囚心锁ツ
囚心锁ツ 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:28

    Try this:

     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.

提交回复
热议问题