Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Prawn: The Pure Ruby PDF Generation Library

By Peter Cooper / August 4, 2008

prawn.png

Prawn is a new pure Ruby PDF generation library developed primarily by Gregory Brown.

Back in March, Gregory tried to raise $13000 so he could spend six months working on Ruby-related open source projects. He eventually raised $5525 from the community (plus $5000 from Ruby Central and $500 from Mountain West RubyConf) and has spent the last few months working on Prawn.

Prawn can be installed from a pull from GitHub or, for those of us who are less adventurous, with a gem install prawn. Once installed, you can give it a quick test run:

require 'prawn'

Prawn::Document.generate("test.pdf") do
  font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
  text "this is a test " * 100
end

Prawn comes with 11 typefaces, including Helvetica, Courier, DejaVuSans, Times, and everyone's favorite - Comic Sans. It already supports image embedding, table drawing, and content positioning, but a lot more is yet to come. Prawn is now ripe for more community involvement and support, so if you want to help (Gregory's looking for a logo!) the prawn-ruby Google Group is a great place to start.

Update: Gregory has created the "Prawn Gallery" on GitHub as a place for people to show off their Prawn-created PDFs.

Comments

  1. hk says:

    For crying out loud, it is either this:

    Prawn can be pulled using git

    or

    Prawn can be pulled from Github

    Understand?

    You can't "pull" from "Git". Git is a program. You might use it to pull something, although unless you have it already you'd probably clone first, THEN pull. Saying "pull from Git" is like saying "download from Safari".

    Secondly, Github is NOT git. It is a great website (although beginning to suffer reliability problems) but it is not git itself. Can you please stop confusing the two? It's like people who think IE is the internet.

    That said, prawn looks like a great tool and I look forward to trying it out.

  2. Peter Cooper says:

    Can you please stop confusing the two?

    It was a one-off typo. Thanks for pointing it out, but a patronizing diatribe wasn't necessary.

  3. Pavel says:

    For me key question: does prawn support utf-8?

  4. Peter Cooper says:

    Yes. Check out the main Prawn link above. It's the second section on the page.

  5. Gregory Brown says:

    Hi Peter,

    Thanks so much for posting this. It's worth mentioning that Mountain West RubyConf also donated $500, not listed on the Pledgie.

    -greg

  6. John Smith says:

    hk - every little outburst like that supports ***'s claim.

  7. Peter Cooper says:

    Gregory: Didn't know that - added - thanks!

  8. thorny_sun says:

    Hey Peter--
    Hope you don't mind the plug, but it seemed relevant. Just in case you didn't know, there also exists an unofficial but worthy rails sister plugin-- prawnto. It lets you create compiled pdf views leveraging the prawn library.
    http://cracklabs.com/prawnto
    http://github.com/thorny-sun/prawnto.git

    hope it helps the rails folks out there... enjoy!
    -thorny_sun

  9. thorny_sun says:

    oops-- that last github link was meant to be:
    http://github.com/thorny-sun/prawnto

  10. Sean says:

    Insanity Prawn Boy -- exactly what I think of every time this library gets mentioned :).

  11. Gregory Brown says:

    Oh man... I've never seen that cartoon before. Disturbing and wonderful all at the same time.

  12. Markus Arike says:

    hk - your role as "language police" is not at all becoming, especially since this is a free website that Mr. Cooper is good enough to provide for us and with which he does a remarkable job.

    I installed Prawn PDF library last night. It works as advertised on Leopard. Nice work and congratulation to Gregory Brown.

  13. Herculano P. Chavez says:

    I'm testing the Rghost is cool to use the ttf fonts inside of pdf

  14. Captain Semantics says:

    You can checkout from subversion, so why can't you pull from git? Discrimination?

  15. carlity says:

    I cant image why one would want a rails plugin for prawn. I really dislike all these little small rails plugins. just use the original library!!!!! on a site note, i hate installing from github with name-gem.git then require gem.git. what a mess. All these ruby innovations are great, but not the huge mess its creating.

  16. Peter Cooper says:

    Captain Semantics: To be fair to hk's original point, if someone were to be as technically pedantic as he was then "checkout from subversion" should really be "checkout from [a/this/their/our] Subversion repository." Of course, we're not that pedantic, so we'll all let it slide ;-)

  17. Johannes Fahrenkrug says:

    This looks great, thanks for your work, Gregory!

  18. Gregory Brown says:

    @carlity,

    Prawnto just makes templates a little easier. Not exactly something that I feel I need, but useful for those who like that sort of thing.

    Also, I agree, the name-gem thing on Git is a little weird. Very useful for *unofficial* gems but I can't see hosting a project that way officially. So Prawn is not using that feature, it has a normal gem on RubyForge.

  19. Ricardo says:

    Just one thing:

    can I put in one line a text with 2 or more color like:

    Name: My Name

    ?

    regards

  20. Ricardo says:

    ops

    like:

    | blue | Name: | \ blue | | green | My name | \ green |

  21. Zach says:

    What great timing; I was going to implement PDF generation this weekend. Thanks Gregory!

  22. Tom Dickie says:

    Any one actually know how to put this into a Rails app? Sorry if this is totally stupid of me, but I don't know if this code goes in the controller or the view or model or where... sorry. The docs don't appear to say either unless I've missed something...

Other Posts to Enjoy

Twitter Mentions