Module: ThecoreDownloadDocuments

Defined in:
lib/thecore_download_documents.rb,
lib/thecore_download_documents/railtie.rb,
lib/thecore_download_documents/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
'0.1.3'

Class Method Summary collapse

Class Method Details

.csv_table(rows, table_headers, filename) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/thecore_download_documents.rb', line 43

def self.csv_table rows, table_headers, filename
  csv = CSV.generate do |row|
    rows.unshift(table_headers).each do |data|
      row << data
    end
  end

  return csv, {filename: "#{filename}.csv", type: "text/csv"}
end

.pdf_table(header, footer, rows, table_headers, filename) ⇒ Object

Your code goes here…



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/thecore_download_documents.rb', line 9

def self.pdf_table header, footer, rows, table_headers, filename
  pdf = Prawn::Document.new page_layout: :landscape, page_size: "A4"
  pdf.repeat :all do
    # Header
    pdf.bounding_box [pdf.bounds.left, pdf.bounds.top], width: pdf.bounds.width do
      pdf.float do
        pdf.text (header[:left] || ""), size: 8, align: :left
      end
      pdf.float do
        pdf.text (header[:center] || ""), size: 8, align: :center
      end
      pdf.text (header[:right] || ""), size: 8, align: :right
    end
    # Footer
    pdf.bounding_box [pdf.bounds.left, pdf.bounds.bottom + 18], width: pdf.bounds.width do
      pdf.float do
        pdf.text (footer[:left] || ""), size: 8, align: :left
      end
      pdf.float do
        pdf.text (footer[:center] || ""), size: 8, align: :center
      end
      pdf.text (footer[:right] || ""), size: 8, align: :right
    end
  end
  
  # Create another box that is placed on the page after our footer is
  pdf.bounding_box [pdf.bounds.left, pdf.bounds.top-8], width: pdf.bounds.width, height: pdf.bounds.height - 16 do
    #Generate the rest of your PDF content here
    pdf.table rows.unshift(table_headers), header: true do |table| table.row(0).font_style = :bold end
  end

  return pdf.render, {filename: "#{filename}.pdf", type: "application/pdf"}
end