I want to generate a document with prawn that uses a PDF template.
I get no errors, but the template is completely ignored. Does anyone know why this might be? I would really appreciate any help!
class JobPdf < Prawn::Document
def initialize(job)
super()
@job = job
text @job.title
text @job.target_text
end
def render(job)
doc = Prawn::Document.new({template: "#{Rails.root}/app/templates/jobs/layout.pdf"})
doc.text job.title
doc.text job.target_text
doc.render
end
end
Jobs Controller:
def show
@job = Job.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf = JobPdf.new(@job)
send_data pdf.render(@job),
filename: "job#{@job.id}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
Prawn
has removed templates from its core apparently it is possible to use https://github.com/prawnpdf/prawn-templates to still utilize them but note even prawn states that this is "very buggy"