Generating Rich PDFs with Prawn

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

Generating Rich PDFs with Prawn

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

7a0d58870c43323ed595feb7729f1246?s=128

Matthew Bass

August 18, 2009
Tweet

Transcript

  1. Generating Rich PDFs with Prawn Matthew Bass

  2. Should my app even be generating PDFs?

  3. The alternatives... • PDF::Writer http://ruby-pdf.rubyforge.org/pdf-writer/ • Ruby FPDF http://zeropluszero.com/software/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... http://prawn.majesticseacreature.com

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

    guy who brought us Ruport • Ruby Mendicant project
  9. The gems... prawn-core http://prawn.majesticseacreature.com prawn-layout http://github.com/sandal/prawn-layout/ prawn-format http://github.com/sandal/prawn-format/

  10. Installation Options # Clone from the repository git clone git://github.com/sandal/prawn.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... http://github.com/tobi/delayed_job/ # Run

    queued jobs rake jobs:work
  29. Conclusion!

  30. Matthew Bass matthewbass.com ©2009 Adeptware, Inc.