Generate PDF from Rails

前端 未结 10 1295
醉酒成梦
醉酒成梦 2020-12-02 06:36

The Ruby On Rails Wiki lists a couple of libraries that facilitate PDF generation in Rails. I need to print out address labels (in letter f

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 07:12

    Prawn is the way to go. Now with prawn-labels that is really easy to do.

    Check out the project's README here:

    https://github.com/jordanbyron/prawn-labels#readme

    This is a super simple example being used in a Rails controller. Don't forget to add gem 'prawn-labels' to your Gemfile.

    names = %w{Jordan Kelly Greg Bob}
    
    labels = Prawn::Labels.render(names, :type => "Avery5160") do |pdf, name|
      pdf.text name
    end
    
    send_data labels, :filename => "names.pdf", :type => "application/pdf"
    

提交回复
热议问题