|
|
@ -1,7 +1,32 @@ |
|
|
|
#!/usr/bin/env ruby |
|
|
|
|
|
|
|
# try to make a sparkfun invoice using prawn |
|
|
|
|
|
|
|
require 'rubygems' |
|
|
|
require 'json' |
|
|
|
require 'prawn' |
|
|
|
pdf = Prawn::Document.new |
|
|
|
pdf.text("sparkfun invoice motherfuckers") |
|
|
|
pdf.render_file('testinvoice.pdf') |
|
|
|
|
|
|
|
class SparkPDF |
|
|
|
|
|
|
|
def spit (structure) |
|
|
|
Prawn::Document.generate('testinvoice.pdf', :page_layout => :portrait) do |
|
|
|
font "Courier" |
|
|
|
text "SparkFun Invoice", :at => [10, 20] |
|
|
|
image "logo.png", :width => 84, :height => 52 |
|
|
|
|
|
|
|
structure.each do |thing| |
|
|
|
text thing |
|
|
|
end |
|
|
|
|
|
|
|
number_pages "<page> of <total>", [bounds.right - 50, bounds.top - 10] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
# test code |
|
|
|
fakeinput = JSON ['bar', 'foo', 'baz'] |
|
|
|
structure = JSON fakeinput |
|
|
|
document = SparkPDF.new |
|
|
|
document.spit(structure) |
|
|
|
|