class Decidim::Exporters::PDF

Exports a PDF using the provided hash, given a collection and a Serializer. This is an abstract class that should be inherited to create PDF exporters, with each PDF exporter class setting the desired template, layout and orientation.

Public Instance Methods

export() click to toggle source

Public: Exports a PDF version of the collection by rendering the template into html and then converting it to PDF.

Returns an ExportData instance.

# File lib/decidim/exporters/pdf.rb, line 17
def export
  html = controller.render_to_string(
    template: template,
    layout: layout,
    locals: locals
  )

  document = WickedPdf.new.pdf_from_string(html, orientation: orientation)

  ExportData.new(document, "pdf")
end
layout() click to toggle source

implementing classes should return a valid ERB path here

# File lib/decidim/exporters/pdf.rb, line 40
def layout
  raise NotImplementedError
end
locals() click to toggle source

This method may be overwritten if the template needs more local variables

# File lib/decidim/exporters/pdf.rb, line 45
def locals
  { collection: collection }
end
orientation() click to toggle source

may be overwritten if needed

# File lib/decidim/exporters/pdf.rb, line 30
def orientation
  "Portrait"
end
template() click to toggle source

implementing classes should return a valid ERB path here

# File lib/decidim/exporters/pdf.rb, line 35
def template
  raise NotImplementedError
end

Protected Instance Methods

controller() click to toggle source
# File lib/decidim/exporters/pdf.rb, line 51
def controller
  raise NotImplementedError
end