|
|
|
@ -14,14 +14,15 @@ module Squib |
|
|
|
# @return [nil] |
|
|
|
# @return [nil] |
|
|
|
# @api public |
|
|
|
# @api public |
|
|
|
def save_pdf(opts = {}) |
|
|
|
def save_pdf(opts = {}) |
|
|
|
p = needs(opts, [:file_to_save, :creatable_dir, :margin, :gap, :trim]) |
|
|
|
p = needs(opts, [:range, :file_to_save, :creatable_dir, :margin, :gap, :trim]) |
|
|
|
width = 11 * @dpi ; height = 8.5 * @dpi #TODO: allow this to be specified too |
|
|
|
width = 11 * @dpi |
|
|
|
|
|
|
|
height = 8.5 * @dpi #TODO: allow this to be specified too |
|
|
|
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", width, height)) |
|
|
|
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", width, height)) |
|
|
|
x = p[:margin] ; y = p[:margin] |
|
|
|
x = p[:margin] |
|
|
|
|
|
|
|
y = p[:margin] |
|
|
|
@progress_bar.start("Saving PDF to #{p[:dir]}/#{p[:file]}", p[:range].size) do |bar| |
|
|
|
@progress_bar.start("Saving PDF to #{p[:dir]}/#{p[:file]}", p[:range].size) do |bar| |
|
|
|
@cards.each_with_index do |card, i| |
|
|
|
p[:range].each do |i| |
|
|
|
surface = trim(card.cairo_surface, p[:trim], @width, @height) |
|
|
|
surface = trim(@cards[i].cairo_surface, p[:trim], @width, @height) |
|
|
|
cc.set_source(surface, x, y) |
|
|
|
cc.set_source(surface, x, y) |
|
|
|
cc.paint |
|
|
|
cc.paint |
|
|
|
bar.increment |
|
|
|
bar.increment |
|
|
|
@ -30,7 +31,8 @@ module Squib |
|
|
|
x = p[:margin] |
|
|
|
x = p[:margin] |
|
|
|
y += surface.height + p[:gap] |
|
|
|
y += surface.height + p[:gap] |
|
|
|
if y > (height - surface.height - p[:margin]) |
|
|
|
if y > (height - surface.height - p[:margin]) |
|
|
|
x = p[:margin] ; y = p[:margin] |
|
|
|
x = p[:margin] |
|
|
|
|
|
|
|
y = p[:margin] |
|
|
|
cc.show_page #next page |
|
|
|
cc.show_page #next page |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|