Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Generating Rich PDFs with Prawn
Search
Matthew Bass
August 18, 2009
0
53
Generating Rich PDFs with Prawn
Leverage Prawn from your Ruby scripts to generate rich, professional-looking PDFs.
Matthew Bass
August 18, 2009
Tweet
Share
More Decks by Matthew Bass
See All by Matthew Bass
Homesteading for Freelancers
pelargir
1
38
A/B Testing for Developers
pelargir
1
41
Homesteading: The New Entrepreneurial Model
pelargir
1
29
Pragmatic Pair Programming
pelargir
3
79
Chaotic Agility
pelargir
1
48
Distance Education: An Alternative to Traditional College
pelargir
0
45
Teascript: A Homesteader's Story
pelargir
1
31
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
60
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
37
2.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
16
2.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
[RailsConf 2023] Rails as a piece of cake
palkan
23
4k
Agile that works and the tools we love
rasmusluckow
325
20k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
A designer walks into a library…
pauljervisheath
200
23k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
Transcript
Generating Rich PDFs with Prawn Matthew Bass
Should my app even be generating PDFs?
The alternatives... • PDF::Writer http://ruby-pdf.rubyforge.org/pdf-writer/ • Ruby FPDF http://zeropluszero.com/software/fpdf/ •
And... that’s it?
PDF::Writer • The best choice for a long time... •
Much slower than Prawn • Markup isn’t as nice
• Port of FPDF written in PHP • Nice logo?
• ???
Prawn gives you PDF goodness... • Fast • Clean syntax*
• Image embedding, tables, etc. • Full UTF-8 support • PNGs with alpha transparencies
Caveat... http://prawn.majesticseacreature.com
History... • Founded April, 2008 by Gregory Brown • ...the
guy who brought us Ruport • Ruby Mendicant project
The gems... prawn-core http://prawn.majesticseacreature.com prawn-layout http://github.com/sandal/prawn-layout/ prawn-format http://github.com/sandal/prawn-format/
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...
Kickin’ it up a notch... Installation Options rake gems:install rake
gems:unpack # optional
Or configure your Rails project for the latest release of
prawn-core and extensions... Installation Options rake gems:install rake gems:unpack # optional
What can it do?
Tables... Exact positioning... Italic, bold, etc... Drawing...
Image embedding... Background colors... UTF-8...
Rails integration...
Inline HTML formatting with prawn-format Speed observations... it’s faster!
Code Examples
Text...
Positioning...
Drawing...
Colors...
Embedding images...
prawn-layout Adds support for tables, grid layouts, etc.
prawn-format Adds support for inline formatting w/HTML tags
prawnto some_controller.rb default.prawn Tasty with Rails! Use helpers, instance vars,
etc. in your views
Bugs & Gotchas • Adobe Reader incompatibilities • Occasional UTF-8
errors • Spotty error handling • prawn-format doesn’t like some chars (gt, lt)
Background Processing Can’t beat delayed_job for simplicity... http://github.com/tobi/delayed_job/ # Run
queued jobs rake jobs:work
Conclusion!
Matthew Bass matthewbass.com ©2009 Adeptware, Inc.