Overriding the Rendering Class

If you have a pre-built report that you want to use, or you want a wrapper around Prawn::Document such as Jamabalya this can be accomplished with the :renderer option. Unlike the other options :renderer is not passed into the constructor when creating the PDF class, instead the class passed in with the :renderer option is used in place of Prawn::Document

Example:

application_helper.rb
class Override < Prawn::Document
  def initialize(opts={})
    super(opts)
    text "I can override the rendering class"
    text "This lets me use pre-built reports and other wrappers around Prawn::Document"
  end
end

app/views/demos/override.pdf.prawn:

prawn_document(:renderer => ApplicationHelper::Override, :page_layout => :landscape) do |pdf|
  pdf.text "I can also continue to add text inside the block"
end
Download PDF

Back To Index