A fixed height could be used, but only if the height of the text is fixed. Only the first line of the text will be printed.
Example:
pdf.table(entries, :cell_style => {:height => 25})
Another option is to use a custom wrapper. Details are here:
https://github.com/prawnpdf/prawn/blob/master/lib/prawn/text/formatted/box.rb#L149
Example:
module MyWrap
def wrap(array)
initialize_wrap(array)
@line_wrap.wrap_line(:document => @document,
:kerning => @kerning,
:width => available_width,
:arranger => @arranger)
if enough_height_for_this_line?
move_baseline_down
print_line
end
@text = @printed_lines.join("\n")
@everything_printed = @arranger.finished?
@arranger.unconsumed
end
end
Prawn::Text::Formatted::Box.extensions << MyWrap
entries = [ ["very long text here", "another very long text here"] ]
Prawn::Document.generate("test.pdf") do
table entries, :cell_style => { :inline_format => true }
end
I just copy the original wrap
method and remove the while
loop in order to print only the first line of the text.
Note that :inline_format => true
must be used in order to get Prawn::Text::Formatted::Box
working.