Module: ThecoreDownloadPdfCommons

Defined in:
lib/thecore_download_pdf_commons.rb,
lib/thecore_download_pdf_commons/engine.rb,
lib/thecore_download_pdf_commons/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

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

Your code goes here…



8
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
# File 'lib/thecore_download_pdf_commons.rb', line 8

def self.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