Created
July 11, 2012 18:51
-
-
Save breckenedge/3092340 to your computer and use it in GitHub Desktop.
PDF Concatenation with Prawn - Slow Example
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
require 'rubygems' | |
require 'benchmark' | |
require 'bundler' | |
Bundler.setup | |
require 'prawn' | |
require 'ruby-debug' | |
sources = ['ML091590492.pdf', 'file1.pdf', 'file2.pdf'] | |
document = Prawn::Document.new(:template => sources.first) | |
sources[1..(sources.length - 1)].each do |file| | |
document.go_to_page(document.page_count) | |
object_store = Prawn::Core::ObjectStore.new(:template => file) | |
num_pages = object_store.page_count | |
(1..num_pages).each do |page_number| | |
document.start_new_page(:template => file, :template_page => page_number) | |
end | |
end | |
document.render_file('out.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's a bit faster if you load the first document as a template