Skip to content

Instantly share code, notes, and snippets.

@jonahgeorge
Created January 11, 2014 00:44
Show Gist options
  • Save jonahgeorge/8365457 to your computer and use it in GitHub Desktop.
Save jonahgeorge/8365457 to your computer and use it in GitHub Desktop.
Ruby Script for appending pdfs with Prawn
#!/usr/bin/ruby
require 'json'
require 'prawn'
raw = File.open("data.json")
json = JSON.parse(raw.read)
Prawn::Document.generate("result.pdf", {:page_size => 'A4', :skip_page_creation => true}) do |pdf|
json["teams"].each do |team|
if File.exists?(team["file"])
nb_pages = Prawn::Document.new(:template => team["file"]).page_count
puts "Appending " + team["file"] + "..."
(1..nb_pages).each do |i|
puts "Page " + i + " / " + nb_pages
pdf.start_new_page(:template => team["file"], :template_page => i)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment