QR Codes are not within the table cells

44 views
Skip to first unread message

Jefferson Francisco

unread,
Feb 16, 2017, 12:12:01 PM2/16/17
to Prawn
I need to place a qr code within the first column of a table for each row. The QR code contains the ID for each organization

I am using the following gems
gem 'prawn'
gem
'prawn-table'
gem
'prawn-qrcode'

Here is my code (I will attach a screenshot below to show my result):

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




Here is the outcome:


Reply all
Reply to author
Forward
0 new messages