Archive

Posts Tagged ‘ruby prawn rubyonrails’

Dashed Lines In Prawn

December 26, 2008 Leave a comment

For a recent project, I’ve been using Prawn, a pretty robust PDF generation utility for Ruby. Generating PDFs is never fun, but Prawn (with the help of Ruby) makes it pretty easy.

One thing lacking in the Prawn library is the ability to make dashed lines. However, the logic of actually creating the dashed line isn’t that complex. You simply draw a solid line, but “pick up” the stroke every few pixels and allow some whitespace. Below is my code for creating multiple dashed lines on a page. It’s pretty simple to see how I’m creating a 2 pixel dash and then skipping 5 pixels forward (leaving 3 pixels of white.)

You can see the output here: dashed_lines.pdf

Categories: ruby Tags: