Created
January 11, 2014 00:44
-
-
Save jonahgeorge/8365457 to your computer and use it in GitHub Desktop.
Ruby Script for appending pdfs with Prawn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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