Browse Source

baby steps

Brennen Bearnes 10 years ago
parent
commit
4c79f30d82
2 changed files with 28 additions and 3 deletions
  1. 28
    3
      invoice.rb
  2. BIN
      logo.png

+ 28
- 3
invoice.rb View File

@@ -1,7 +1,32 @@
1 1
 #!/usr/bin/env ruby
2 2
 
3
+# try to make a sparkfun invoice using prawn
4
+
3 5
 require 'rubygems'
6
+require 'json'
4 7
 require 'prawn'
5
-pdf = Prawn::Document.new
6
-pdf.text("sparkfun invoice motherfuckers")
7
-pdf.render_file('testinvoice.pdf')
8
+
9
+class SparkPDF
10
+
11
+  def spit (structure)
12
+    Prawn::Document.generate('testinvoice.pdf', :page_layout => :portrait) do
13
+      font "Courier"
14
+      text "SparkFun Invoice", :at => [10, 20]
15
+      image "logo.png", :width => 84, :height => 52
16
+
17
+      structure.each do |thing|
18
+        text thing
19
+      end
20
+
21
+      number_pages "<page> of <total>", [bounds.right - 50, bounds.top - 10] 
22
+    end
23
+  end
24
+
25
+end
26
+
27
+# test code
28
+fakeinput = JSON ['bar', 'foo', 'baz']
29
+structure = JSON fakeinput
30
+document = SparkPDF.new
31
+document.spit(structure)
32
+

BIN
logo.png View File


Loading…
Cancel
Save