require 'prawn/qrcode'
class ReportPdf < Prawn::Document
def initialize(organizations)
super()
@organizations = organizations
header
text_content
table_content
end
def header
image "#{Rails.root}/app/assets/images/logo.png", width: 530, height: 150
end
def text_content
y_position = cursor - 50
bounding_box([0, y_position], :width => 270, :height => 300) do
text "Organizaciones", size: 15, style: :bold
text "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
end
bounding_box([300, y_position], :width => 270, :height => 300) do
text "Duis vel", size: 15, style: :bold
text "Duis vel tortor elementum, ultrices tortor vel, accumsan dui."
end
end
def table_content
table organization_rows do
row(0).font_style = :bold
self.header = true
self.row_colors = ['DDDDDD', 'FFFFFF']
self.column_widths = [40, 300, 200]
end
end
def organization_rows
[['#', 'Name', 'id']] +
@organizations.map do |organization|
[render_qr_code(RQRCode::QRCode.new(organization.id.to_s, :size => 2)).to_s,
organization.name,
organization.id]
end
end
end