【问题标题】:How to draw a horizontal line using prawn/rails on X axis at a specific point如何在特定点的 X 轴上使用虾/导轨绘制水平线
【发布时间】:2018-07-17 21:33:00
【问题描述】:
用户可以为页面指定一个边距底部,我希望能够绘制一条水平线来显示他们放置它的位置。我在我的 PDF 文档(A4 大小)中定义了 margin_bottom。
我需要做的就是将指定的边距添加到 X 轴并画一条线。但是,我怎样才能画出这条线呢?
据我所知,我可以这样称呼
stroke_horizontal_line(0, 0 + margin_bottom)
但是,这不起作用,我需要它是页面的整个宽度。
【问题讨论】:
标签:
ruby-on-rails
pdf
prawn
【解决方案1】:
首先,我认为stroke_horizontal_line 的工作方式与您的想法有些不同(如果我理解您正在尝试正确执行的操作)
stroke_horizontal_line(x1, x2, at: y) 在y 的垂直高度绘制一条从x1 到x2 的水平线,其中y 从文档底部的0 开始(在底部边距之后,而不是在页面底部)。
所以,我认为您正在尝试在整个页面上绘制一条水平线,该高度由某个变量 margin_bottom 定义,以使用 stroke_horizontal_line 完成此操作,您可以这样做:
# You can set a stroke color, if you set it to white it is possible that you just
# forgot to set it back to black.
stroke_color 0, 0, 0, 100
# You can also set the line width
line_width 2
# This would draw a horizontal line across the whole page (not over your side margins)
# at the height of margin_bottom + your document bottom margin (measured from the bottom up)
stroke_horizontal_line(0, bounds.width, at: margin_bottom)
您也可以使用stroke_horizontal_rule,它只会在您当前的光标位置绘制一条水平线,因此您必须在使用该方法之前将光标放在正确的位置。
【解决方案2】:
简单。
stroke_horizontal_line (y), (y), at: (x)
【解决方案3】:
stroke_horizontal_rule
应该这样做。