-
-
Save sahidursuman/ea29a0e9e4a8547a37887800c958f49a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MaRuKu::Out::Prawn | |
def to_prawn(pdf) | |
@pdf = pdf | |
@pdf.font_size = 11 | |
array_to_prawn(@children) | |
end | |
def array_to_prawn(children) | |
children.each do |c| | |
send("to_prawn_#{c.node_type}", c) | |
end | |
end | |
def to_prawn_paragraph(para) | |
@pdf.text para.children.join("\n") | |
@pdf.text ' ' | |
end | |
def to_prawn_entity(entity) | |
puts "Didn't write entity to pdf" | |
p entity | |
end | |
# TODO find a less ghetto way to do leading-trailing margins | |
def to_prawn_header(header) | |
size = { 1 => 16, 2 => 14 }[header.level] | |
@pdf.text header.children.join("\n"), :size => size, :style => :bold | |
@pdf.text ' ' | |
end | |
def to_prawn_div(div) | |
if div.attributes[:class] == "signature" | |
signature_name = div.children.map.join(" ") | |
@pdf.instance_eval do | |
text ' ', :size => 30 | |
stroke_horizontal_line 0, 200 | |
stroke_horizontal_line 250, 300 | |
text ' ', :size => 4 | |
text signature_name | |
draw_text "Date", :at => [250, y - bounds.absolute_bottom + 5] | |
text ' ', :size => 20 | |
stroke_horizontal_line 0, 200 | |
text ' ', :size => 4 | |
text signature_name + " (Print)" | |
end | |
else | |
puts "Didn't write div to pdf: #{div.inspect}" | |
end | |
end | |
end | |
MaRuKu::MDElement.send(:include, MaRuKu::Out::Prawn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment