Prawn doesn't draw a horizontal rule
Asked Answered
S

1

12

I want to draw a simple horizontal rule. What I'm doing is:

move_down 30
horizontal_rule

and Gemfile

gem 'prawn', :git => "https://github.com/prawnpdf/prawn.git", branch: 'master' 

It doesn't draw anything.

Soliloquy answered 29/9, 2013 at 1:34 Comment(0)
M
36

You need to call horizontal_rule inside a stroke do block, i.e.

stroke do
  move_down 30
  horizontal_rule
end

Alternatively you can call the method, stroke_horizontal_rule.

move_down 30    
stroke_horizontal_rule

If you want to use other options such as color, width etc I think you have to do it in the block...

stroke do
  stroke_color 'ff0000'
  dash(5, space: 2, phase: 0)
  line_width 10
  stroke_horizontal_rule
  move_down 15
  horizontal_line(0, 540)
end
Misestimate answered 29/9, 2013 at 2:50 Comment(3)
is it possible to specify its color, width?Soliloquy
but what about its width?Soliloquy
The width is in the example... Are you talking about the length? The horizontal_rule spans the width of its bounds. If you need to specify length you'll either have to create a bounding_box to contain the horizontal_rule, or use the horizontal_line which lets you specify start and end points (and therefore line length)Misestimate

© 2022 - 2024 — McMap. All rights reserved.