Skip to content

Instantly share code, notes, and snippets.

@gioele
Created January 15, 2012 13:43
Show Gist options
  • Save gioele/1615898 to your computer and use it in GitHub Desktop.
Save gioele/1615898 to your computer and use it in GitHub Desktop.
Show "last line" rendering problem in Prawn
#!/usr/bin/env ruby
require 'prawn'
require "prawn/measurement_extensions"
paper_sizes = {
'A4' => [210, 297],
'A5' => [148, 210],
'A6' => [105, 148],
# XXX: if you uncomment B5, the A6 line will be shown and
# the one for B5 will not.
#'B5' => [176, 250],
}
def arrow_line(pdf)
bb = pdf.bounds
v_center = pdf.cursor + 0.8.mm
#---
pdf.line [bb.left, v_center],
[bb.right, v_center]
end
pdf = Prawn::Document.new(:page_size => 'A4', :margin => 0)
paper_sizes.to_a.sort.each { |name, size|
width, height = *size
format = name.first
pdf.bounding_box [0, height.mm], :width => width.mm, :height => height.mm do
pdf.stroke_bounds
pdf.pad(1.mm) do
pdf.text name, :align => :right
end
arrow_line(pdf)
pdf.move_up 2.mm
pdf.text "here should be the line for #{name}"
end
}
pdf.render_file "test.pdf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment