ruby-on-railspdfprawnprawnto

Working with signature fields using Prawn and Rails


Signature fields in two columnsI'm trying to draw a set of signature fields at the bottom of page with terms and conditions. I'm brand new to Prawn so I'm having a little trouble with this. I looked at the column_box method and there looks like there is some left_side and right_side methods in some of the documentation but those methods don't seem to be working (I get a NoMethodError) or something.

What I want is two signature fields with text underneath each. One of the left side of the page and one on the right side. How do I do this?

My code sample:

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

And the error I'm getting:

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

Solution

  • You could make your column_box having 2 columns, then adjust height matching the size of underlines and the text below it, so it would break columns between them. It would be something like:

    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
    

    This outputs:Foo Bar divided in two columns

    Don't forget you have to specify :columns => 2 and height attributes of column_box for desired 2-column effect.