使用Prawn和Rails处理签名字段

时间:2017-01-30 22:31:58

标签: ruby-on-rails pdf prawn prawnto

http://plnkr.co/edit/jtMdP3E2LJMBs6CzBzLQ?p=preview我试图在页面底部绘制一组带有条款和条件的签名字段。我是Prawn的新手,所以我对此有点麻烦。我查看了column_box方法,看起来在某些文档中有一些left_sideright_side方法,但这些方法似乎不起作用(我得到了一个NoMethodError)或其他什么。

我想要的是两个签名字段,每个字段下面都有文字。页面左侧之一,右侧之一。我该怎么做?

我的代码示例:

column_box([0, cursor], :columns => 2, :width => bounds.width) do
    text "_______________________"
    text "Signature 1"
    right_side
    text "_______________________"
    text "Signature 2"
end

我得到的错误:

undefined local variable or method `right_side' for #<Prawnto::TemplateHandlers::Renderer:0x00000005b3a420>

1 个答案:

答案 0 :(得分:3)

您可以使column_box具有2列,然后调整高度以匹配下划线的大小及其下方的文本,这样就会打破它们之间的列。 它会是这样的:

Prawn::Document.generate("hello.pdf") do
    column_box([0, cursor],:columns => 2, :width => bounds.width, :height => 75) do
        # For default font 2x 25px lines are enough to break an 75px height column
        # You should adjust height of the box and font_size to match
        # your desired 2-column effect
        font_size 25
        text("___________")
        text("Foo")
        text("___________")
        text("Bar")
    end
end

输出:Foo Bar divided in two columns

不要忘记您必须为:columns => 2指定heightcolumn_box属性以获得所需的2列效果。