Generating Rich PDFs with Prawn

7a0d58870c43323ed595feb7729f1246?s=47 Matthew Bass
August 18, 2009

Generating Rich PDFs with Prawn

Leverage Prawn from your Ruby scripts to generate rich, professional-looking PDFs.


Matthew Bass

August 18, 2009


  1. Generating Rich PDFs with Prawn Matthew Bass

  2. Should my app even be generating PDFs?

  3. The alternatives... • PDF::Writer • Ruby FPDF •

    And... that’s it?
  4. PDF::Writer • The best choice for a long time... •

    Much slower than Prawn • Markup isn’t as nice
  5. • Port of FPDF written in PHP • Nice logo?

    • ???
  6. Prawn gives you PDF goodness... • Fast • Clean syntax*

    • Image embedding, tables, etc. • Full UTF-8 support • PNGs with alpha transparencies
  7. Caveat...

  8. History... • Founded April, 2008 by Gregory Brown • ...the

    guy who brought us Ruport • Ruby Mendicant project
  9. The gems... prawn-core prawn-layout prawn-format

  10. Installation Options # Clone from the repository git clone git://

    # Install the gem directly sudo gem install prawn Keepin’ it simple...
  11. Kickin’ it up a notch... Installation Options rake gems:install rake

    gems:unpack # optional
  12. Or configure your Rails project for the latest release of

    prawn-core and extensions... Installation Options rake gems:install rake gems:unpack # optional
  13. What can it do?

  14. Tables... Exact positioning... Italic, bold, etc... Drawing...

  15. Image embedding... Background colors... UTF-8...

  16. Rails integration...

  17. Inline HTML formatting with prawn-format Speed observations... it’s faster!

  18. Code Examples

  19. Text...

  20. Positioning...

  21. Drawing...

  22. Colors...

  23. Embedding images...

  24. prawn-layout Adds support for tables, grid layouts, etc.

  25. prawn-format Adds support for inline formatting w/HTML tags

  26. prawnto some_controller.rb default.prawn Tasty with Rails! Use helpers, instance vars,

    etc. in your views
  27. Bugs & Gotchas • Adobe Reader incompatibilities • Occasional UTF-8

    errors • Spotty error handling • prawn-format doesn’t like some chars (gt, lt)
  28. Background Processing Can’t beat delayed_job for simplicity... # Run

    queued jobs rake jobs:work
  29. Conclusion!

  30. Matthew Bass ©2009 Adeptware, Inc.