Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pdf = Prawn::Document.new do
- text "The Prince", :align => :center, :size => 48
- text "Niccolò Machiavelli", :align => :center, :size => 20
- move_down 42
- column_box([0, cursor], :columns => 3, :width => bounds.width) do
- text((<<-END.gsub(/s+/, ' ') + "nn") * 20)
- All the States and Governments by which men are or ever have been ruled,
- have been and are either Republics or Princedoms. Princedoms are either
- hereditary, in which the bla bla bla bla .....
- END
- end
- end.render
- module Prawn
- class Document
- def reflow_column_box(*args, &block)
- init_column_box(block) do |parent_box|
- map_to_absolute!(args[0])
- @bounding_box = ReflowColumnBox.new(self, parent_box, *args)
- end
- end
- private
- class ReflowColumnBox < ColumnBox
- def move_past_bottom
- @current_column = (@current_column + 1) % @columns
- @document.y = @y
- if 0 == @current_column
- @y = @parent.absolute_top
- @document.start_new_page
- end
- end
- end
- end
- end
- column_box([0, cursor], :columns => 3, :width => bounds.width) do
- reflow_column_box([0, cursor], :columns => 3, :width => bounds.width) do
- require 'prawn'
- text_to_write = ((<<-END.gsub(/s+/, ' ') + "nn") * 20)
- All the States and Governments by which men are or ever have been ruled,
- have been and are either Republics or Princedoms. Princedoms are either
- hereditary, in which the bla bla bla bla .....
- END
- pdf = Prawn::Document.generate("test.pdf") do
- text "The Prince", :align => :center, :size => 48
- text "Niccolò Machiavelli", :align => :center, :size => 20
- move_down 42
- starting_y = cursor
- starting_page = page_number
- span(bounds.width / 3, position: :left) do
- text_to_write = text_box text_to_write, at: [bounds.left, 0], overflow: :truncate
- end
- go_to_page(starting_page)
- move_cursor_to(starting_y)
- span(bounds.width / 3, position: :center) do
- text_to_write = text_box text_to_write, at: [bounds.left, 0], overflow: :truncate
- end
- go_to_page(starting_page)
- move_cursor_to(starting_y)
- span(bounds.width / 3, position: :right) do
- text_box text_to_write, at: [bounds.left, 0]
- end
- end
- float do
- span((bounds.width / 3) - 20, :position => :left) do
- # Row Table Code
- end
- end
- float do
- span((bounds.width / 3) - 20, :position => :center) do
- # Row Table Code
- end
- end
- float do
- span((bounds.width / 3) - 20, :position => :right) do
- # Row Table Code
- end
- end
- column_box(reflow_margins: true, columns: 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement