Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. pdf = Prawn::Document.new do
  2. text "The Prince", :align => :center, :size => 48
  3. text "Niccolò Machiavelli", :align => :center, :size => 20
  4. move_down 42
  5.  
  6. column_box([0, cursor], :columns => 3, :width => bounds.width) do
  7. text((<<-END.gsub(/s+/, ' ') + "nn") * 20)
  8. All the States and Governments by which men are or ever have been ruled,
  9. have been and are either Republics or Princedoms. Princedoms are either
  10. hereditary, in which the bla bla bla bla .....
  11. END
  12. end
  13. end.render
  14.  
  15. module Prawn
  16. class Document
  17.  
  18. def reflow_column_box(*args, &block)
  19. init_column_box(block) do |parent_box|
  20. map_to_absolute!(args[0])
  21. @bounding_box = ReflowColumnBox.new(self, parent_box, *args)
  22. end
  23. end
  24.  
  25. private
  26.  
  27. class ReflowColumnBox < ColumnBox
  28. def move_past_bottom
  29. @current_column = (@current_column + 1) % @columns
  30. @document.y = @y
  31. if 0 == @current_column
  32. @y = @parent.absolute_top
  33. @document.start_new_page
  34. end
  35. end
  36. end
  37. end
  38. end
  39.  
  40. column_box([0, cursor], :columns => 3, :width => bounds.width) do
  41.  
  42. reflow_column_box([0, cursor], :columns => 3, :width => bounds.width) do
  43.  
  44. require 'prawn'
  45.  
  46. text_to_write = ((<<-END.gsub(/s+/, ' ') + "nn") * 20)
  47. All the States and Governments by which men are or ever have been ruled,
  48. have been and are either Republics or Princedoms. Princedoms are either
  49. hereditary, in which the bla bla bla bla .....
  50. END
  51.  
  52. pdf = Prawn::Document.generate("test.pdf") do
  53. text "The Prince", :align => :center, :size => 48
  54. text "Niccolò Machiavelli", :align => :center, :size => 20
  55. move_down 42
  56.  
  57. starting_y = cursor
  58. starting_page = page_number
  59.  
  60. span(bounds.width / 3, position: :left) do
  61. text_to_write = text_box text_to_write, at: [bounds.left, 0], overflow: :truncate
  62. end
  63.  
  64. go_to_page(starting_page)
  65. move_cursor_to(starting_y)
  66.  
  67. span(bounds.width / 3, position: :center) do
  68. text_to_write = text_box text_to_write, at: [bounds.left, 0], overflow: :truncate
  69. end
  70.  
  71. go_to_page(starting_page)
  72. move_cursor_to(starting_y)
  73.  
  74. span(bounds.width / 3, position: :right) do
  75. text_box text_to_write, at: [bounds.left, 0]
  76. end
  77. end
  78.  
  79. float do
  80. span((bounds.width / 3) - 20, :position => :left) do
  81. # Row Table Code
  82. end
  83. end
  84.  
  85. float do
  86. span((bounds.width / 3) - 20, :position => :center) do
  87. # Row Table Code
  88. end
  89. end
  90.  
  91. float do
  92. span((bounds.width / 3) - 20, :position => :right) do
  93. # Row Table Code
  94. end
  95. end
  96.  
  97. column_box(reflow_margins: true, columns: 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement