Generate PDF from Rails

前端 未结 10 1147
醉酒成梦
醉酒成梦 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:26

    I've used both PDF::Writer and Prawn and find Prawn much more pleasant to use. Check out Ruby Mendicant for a comparison that demonstrates the joys of Prawn w/r/t PDF::Writer.

    Actually, just check out Ruby Mendicant anyway for a great design pattern for right livelihood as a developer.

    0 讨论(0)
  • 2020-12-02 07:27

    Though not completely ruby, you could use OpenOffice .odt to generate PDFs by combining serenity and docsplit.

    http://github.com/kremso/serenity

    http://documentcloud.github.com/docsplit/

    Or you could use the clamsy gem which uses odt and cups-pdf to generate the PDF.

    http://github.com/ngty/clamsy

    0 讨论(0)
  • 2020-12-02 07:33

    If you're not doing anything too complex, You could also use HTMLDOC, which converts basic HTML to PDF. This prevents you from having to learn more proprietary layout syntax(like in the case of Prawn). It might save you some headaches :)

    Here's a link to the ruby gem for HTMLDOC:

    • http://htmldoc.rubyforge.org/

    Also, here's a good guide for rendering a view in rails to pdf using HTMLDOC:

    • http://blog.adsdevshop.com/2007/11/20/easy-pdf-generation-with-ruby-rails-and-htmldoc/
    0 讨论(0)
  • 2020-12-02 07:34

    For your use case, I agree with most other answers that prawn is the right choice because you need pixel-level control over the output.

    For generating PDF reports with built-in (opinionated) table styling, headers, etc., you can use the report gem - check out Generate pdf from Rails 3 - what tool to choose? for an example of how to use.

    0 讨论(0)
提交回复
热议问题