Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
DFONT_FILE = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
puts "There are #{Prawn::Font::DFont.font_count(DFONT_FILE)} fonts in #{DFONT_FILE}:"
Prawn::Font::DFont.named_fonts(DFONT_FILE).each do |name|
puts "* #{name}"
end
puts
puts "generating sample document in 'dfont.pdf'..."
Prawn::Document.generate "dfont.pdf" do
DFONT_FILE = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
puts "There are #{Prawn::Font::DFont.font_count(DFONT_FILE)} fonts in #{DFONT_FILE}:"
Prawn::Font::DFont.named_fonts(DFONT_FILE).each do |name|
puts "* #{name}"
end
puts
puts "generating sample document in 'dfont.pdf'..."
Prawn::Document.generate "dfont.pdf" do
# === Text Positioning Details:
#
# When using the :at parameter, Prawn will position your text by its
# baseline, and flow along a single line.
#
# When using automatic text flow, Prawn currently does a bunch of nasty
# hacks to get things to position nicely in bounding boxes, table cells,
# etc.
#
# For AFM fonts, the first line of text is positioned font.height below
require "enumerator"
module LazyStream
class Node
def initialize( head, &promise )
@head, @tail = head, promise
end
attr_reader :head
require "enumerator"
module LazyStream
class Node
def initialize( head, &promise )
@head, @tail = head, promise
end
attr_reader :head
require "open-uri"
Prawn::Document.generate("github-invoice.pdf", :top_margin => 68) do
text "Invoice / Receipt", :size => 24, :style => :bold
move_down 30
text "Account billed: defunkt (chris@ozmm.org)", :size => 14
move_down 20
#!/usr/bin/env ruby
require "pathname"
WORKING_DIR = Pathname.new(".").realpath
LOADER = %Q{
require "pathname"
Pathname.glob("#{WORKING_DIR}/vendor/**/**") do |dir|
lib = dir + "lib"
$LOAD_PATH.push(lib.directory? ? lib : dir)
require "open-uri"
Prawn::Document.generate("remote_images.pdf") do
image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")
end
Prawn::Document.generate("span.pdf") do
# Spans will typically be used outside of bounding boxes as a way to build
# single columns of flowing text that span across pages.
#
span(350, :position => :center) do
text "Here's some centered text in a 350 point column. " * 100
end
# Spans are not really compatible with bounding boxes because they break
require "enumerator"
# tree is represented as: [[a,b,c,d],[e,f,g],[h,i],[j]]
# (bottom up)
#
def max(tree)
bottom = tree.shift
pairs = bottom.enum_for(:each_cons, 2).to_a
update = pairs.enum_for(:each_with_index).map do |pair,i|
tree.first[i] + pair.max