Created
January 11, 2013 18:29
-
-
Save eclosson/4512859 to your computer and use it in GitHub Desktop.
Merging 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
class PdfMerger | |
def merge(pdf_paths, destination) | |
first_pdf_path = pdf_paths.delete_at(0) | |
Prawn::Document.generate(destination, :template => first_pdf_path) do |pdf| | |
pdf_paths.each do |pdf_path| | |
pdf.go_to_page(pdf.page_count) | |
template_page_count = count_pdf_pages(pdf_path) | |
(1..template_page_count).each do |template_page_number| | |
pdf.start_new_page(:template => pdf_path, :template_page => template_page_number) | |
end | |
end | |
end | |
end | |
private | |
def count_pdf_pages(pdf_file_path) | |
pdf = Prawn::Document.new(:template => pdf_file_path) | |
pdf.page_count | |
end | |
end |
I am also getting blank PDFs.
prawn removed support for :template as of 0.14.0 :( causing the blank pages
Officially, Prawn dropped template support, so it will not work.
See more about that: prawnpdf/prawn#376
PS. Sorry, didn't see @bhh post :)
👎🏽
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not getting an error, I'm just getting blank PDFs.