0
votes

I want to create a document with prawn one or more pages long that uses a different template for each page.

Prawn::Document.generate("test.pdf") do
  doc.faces.each do |face|
    start_new_page(:template => face.background_path)
  end
end

This works and creates a document, however the first page is a blank letter sized page and then my pages added with start_new_page show up. Is there a way to have prawn not generate that first page?

thanks!

1

1 Answers

2
votes
pdf = Prawn::Document.new(:skip_page_creation => true)
doc.faces.each do  |face|
  pdf.start_new_page(:template => face.background_path)
  < your page building code here >
end

should work if I'm reading the docs correctly.

My controller code looks like:

def pdf
  @person = Person.find(params[:id])
  send_data @person.as_pdf, :filename => "#{@person.pdfName}.pdf", :type => "application/pdf"
end

and the as_pdf method in person.rb looks like

def as_pdf(type = 'short')
  pdf = Prawn::Document.new(:margin => [36, 36, 36, 36] )
  driver = self.pdf_layout_info
  driver.each do |element|
    < lots of ugly layout logic >
  end
  pdf.render
end