jabbrwcky / prawn-qrcode

An extension to prawn for easy QR Code generation/rendering

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding QR code to a table

jtFrancisco opened this issue · comments

I get the error

Prawn::Errors::UnrecognizedTableContent

When I do this:

require 'prawn/qrcode'

class ReportPdf < Prawn::Document
  def initialize(organizations)
    super()
    @organizations = organizations
    table_content
  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)), organization.name, organization.id]
      end
  end

end

Can anyone help by providing an example of adding a QR code to each row in a table?

I figured out that the render_qr_code needs to_s appended.

So, the new organization_rows code looks like this:

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

However, now I get the following in the PDF. See the screenshot:
screen shot 2017-02-16 at 10 32 12 am

The issue is that the default table only handles a number of data types.

I think I could implement a QRCode Table cell to improve the integration