Class: Decidim::Exporters::PDF

Inherits:
Exporter
  • Object
show all
Defined in:
decidim-core/lib/decidim/exporters/pdf.rb

Overview

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.

Direct Known Subclasses

FormPDF

Instance Method Summary collapse

Methods inherited from Exporter

#initialize

Constructor Details

This class inherits a constructor from Decidim::Exporters::Exporter

Instance Method Details

#exportObject

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

Returns an ExportData instance.



17
18
19
20
21
22
23
24
25
26
27
# File 'decidim-core/lib/decidim/exporters/pdf.rb', line 17

def export
  html = controller.render_to_string(
    template:,
    layout:,
    locals:
  )

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

  ExportData.new(document, "pdf")
end

#layoutObject

implementing classes should return a valid ERB path here

Raises:

  • (NotImplementedError)


40
41
42
# File 'decidim-core/lib/decidim/exporters/pdf.rb', line 40

def layout
  raise NotImplementedError
end

#localsObject

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



45
46
47
# File 'decidim-core/lib/decidim/exporters/pdf.rb', line 45

def locals
  { collection: }
end

#orientationObject

may be overwritten if needed



30
31
32
# File 'decidim-core/lib/decidim/exporters/pdf.rb', line 30

def orientation
  "Portrait"
end

#templateObject

implementing classes should return a valid ERB path here

Raises:

  • (NotImplementedError)


35
36
37
# File 'decidim-core/lib/decidim/exporters/pdf.rb', line 35

def template
  raise NotImplementedError
end