Continuing on a theme, this post brings you the latest news from Prawn, the Ruby PDF library currently being developed under the auspices of the Ruby Mendicant project. The news this time around focuses on m17n progress, TTF font embedding, and some new goodies from contributors. Sexy screenshots and code samples lie just beyond the cut for those who wish to learn more.
What’s new in Proterozoic Prawn?
Have you ever been excited about Comic Sans before? How about its OS X cousin Chalkboard? It’s now time for us to be excited about both:

Prawn is now successfully doing Type0 font embedding for TTF fonts! This is different from PDF::Writer, as no AFM file is needed to process and embed the fonts. Here’s the code that generated the above screenshot:
Prawn::Document.generate "hello-ttf.pdf" do fill_color "0000ff" font "comicsans.ttf" text "Hello World", :at => [200,720], :size => 32 font "Chalkboard.ttf" text "This is chalkboard wrapping " * 20 end
Prawn tries to look for your files in a few convenient places when you call font, but you can always specify an absolute path if it can’t find them.
Because we’re doing Type0 font embedding, we’re able to map unicode codepoints to glyphs, so this means on Ruby 1.8, so long as you pass UTF-8 strings to text() and your font supports unicode mappings, it should be able to display your characters. On Ruby 1.9, Prawn will attempt to convert your string to UTF-8. Though we can’t at this stage claim that we’ve got true m17n support in Prawn, this is a huge step in the right direction, and is the highlight of this development checkpoint.
Though the bulk of the font embedding work was done by James Healy and myself, others have contributed cool stuff too. Michael Daines has tweaked Prawn’s bounding boxes to support dynamic height calculation and nesting, which shows interesting promises for advanced layout features. A new contributor August Lilleaas simplified setting font sizes, resulting in cool code like this:
Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
font 'Helvetica'
font_size! 16
text 'Font at 16 point'
font_size 9 do
text 'Font at 9 point'
text 'Font at manual override 20 point', :size => 20
text 'Font at 9 point'
end
text 'Font at 16 point'
end
This code outputs a PDF that looks something like this:

It is very cool to see convenient features cropping up, especially when I’ve been spending most of my time lumbering around in the low level font embedding coal mines. I certainly hope contributors keep making things more comfortable from the user side of things, it is much appreciated.
In other news, various small bugs were fixed here and there, and some refactoring and documentation work went down. But since we’ve exhausted the exciting stuff, let’s not forget to talk a bit about the future.
Where is Prawn Headed Now?
For those who have been following the development plan, you can see that the general idea is to get Prawn to a suitably usable state so that I can integrate it into Ruport and remove our PDF::Writer dependency. This will likely take a couple more months, though we’ll be taking a more direct route towards this goal in the coming weeks.
The next big milestone will be support for table drawing. We want to build something capable of replacing PDF::Writer’s SimpleTable. The primary focus at first will be performance, and we’ll figure out how to layer in advanced features as we go. I think we can make some improvements to the API for this sort of thing, and maybe even re-think the model entirely. We’d love to get something close to the HTML table model, but that might be too complicated, so we’ll see how things go. The key here is that we want it to be fast, and easy to work with. I think you’ll see something crop up that fits that bill within a couple weeks, but I definitely am looking for folks to share their thoughts with me.
Aside from table drawing, we’ll circle back and fix bugs and clean things up whenever we find the time or when something gets in the way. By the looks of the first screenshot in the post, we’ll need finer grain control over vertical spacing, and possibly better defaults for that. There are some other issues under the hood that need to be addressed, but for a project that hasn’t been released yet, Prawn is pretty solid. People have already commented on the high readability of the code and the documentation quality. We’ll try to keep making those things even better as we go along.
At this point in time, there’s no need to wait on the sideline. If you’re looking to get involved, I’m sure we can think of a few ways:
Join the Prawnversation
I mentioned last time that I started up a Prawn mailing list. We’ve already done some discussion on there and reviewed some experimental features. Feel free to join up and post questions / suggestions or other thoughts.
There is also the #prawn channel on Freenode.net where James Healy and I are always lurking when we’re working on the project. If you’re interested in what we’re doing to Prawn’s guts, you’ll be able to hear plenty of obscure references to parts of the PDF spec combined with obscenities as we do our work.
Finally, watch the project on Github. Watch the main repository, as well as the mdaines, yob, and leethal fork. Having folks watching is really good motivation, having folks create interesting forks is amazing.
Please take advantage of the fact that this is more-or-less my job for the next few months. If you wish to contribute, you will get plenty of attention.
So far I’ve learned that implementing PDF is hard, that Github rocks, and that there are lots of cool people who care about this problem. Even if the first thing doesn’t go away between now and mid-September, the latter two are a pretty good deal.
Until next time, happy hacking with the magnificent sea creature!


Really cool to read these "progress reports" :)
and all with some examples to get others started in it.
@markus,
Glad you enjoy them. All the examples are included with the Prawn source, so please do give them a try and let me know if you have any problems or suggestions.
Cool enough, thanks for the info.
If I see something irregular, alien inside... - like perl code ... - I will let you know :)