Skip to content

Instantly share code, notes, and snippets.

@breckenedge
Created July 11, 2012 18:51
Show Gist options
  • Save breckenedge/3092340 to your computer and use it in GitHub Desktop.
Save breckenedge/3092340 to your computer and use it in GitHub Desktop.
PDF Concatenation with Prawn - Slow Example
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')
@breckenedge
Copy link
Author

it's a bit faster if you load the first document as a template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment