Home > ruby > Dashed Lines In Prawn

Dashed Lines In Prawn

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

Advertisements
Categories: ruby Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: