Change Table Size Prawn

2019-08-26 08:47发布

问题:

Hi guys I'm doing a ruby ​​report using prawn! how can I change the size of the table?

Code:

require "prawn"
require "prawn/table"

logo=Dir.pwd+"/logo.jpg"

arr = ['a', 'aa', 'aaa', 'ddd', 'eee', 'fff']
arr2 = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff']
arr3 = ['a', 'b', 'c', 'd', 'e', 'f']

Prawn::Document.generate("rapportino.pdf") do
  move_down 10
  image logo,:width=>540,:height=>60
  move_down 30
  text "Ragione Sociale:   "+ARGV[0] 
  move_down 30
  text "Nome Cantiere:     "+ARGV[1]
  move_down 30
  text "Note:  "+ARGV[2]
  move_down 30
  table([
  ["Articolo - Risorsa", "Descrizione", "Quantita"],
  *[arr, arr2, arr3]
  .transpose
  ])
end

回答1:

You can pass options hash as a arg to table() specifying the columns width or a width.

options = {column_widths:{ 0 => 125, 1 => 100 }, width: 225}

In your example:

options = {column_widths:{ 0 => 125, 1 => 100 }, width: 225}
arr = ['a', 'aa', 'aaa', 'ddd', 'eee', 'fff']
arr2 = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff']
arr3 = ['a', 'b', 'c', 'd', 'e', 'f']

Prawn::Document.generate("rapportino.pdf") do
  move_down 10
  image logo,:width=>540,:height=>60
  move_down 30
  text "Ragione Sociale:   "+ARGV[0] 
  move_down 30
  text "Nome Cantiere:     "+ARGV[1]
  move_down 30
  text "Note:  "+ARGV[2]
  move_down 30
  table([
    ["Articolo - Risorsa", "Descrizione", "Quantita"],
    *[arr, arr2, arr3]
    .transpose
    ],options)
end