2011-11-11 38 views
4

我正在與Prawn一起生成pdf,我必須在表格的單元格中插入圖像。使用對象在表格中插入圖像時出錯

我的代碼是這樣的:

image = "path to file" 

subject = [["FORMATIVE I "," SUMATIVE ","GRAPH"], 
      [formative_1,sumative, {:image => image}] 
      ] 
table subject 

但是,我得到它說的錯誤:

prawn/table/cell.rb:127:in `make': Content type not recognized: nil (ArgumentError) 

我怎樣才能解決這個問題?任何幫助是極大的讚賞。

乾杯!

+1

青翠,你有沒有想過或找到解決辦法? – derick

回答

4

在當前版本的0.12.0中,不可能在Prawn::Table中嵌入圖像,但此功能似乎正在進行中,請參見here。此刻,你必須編寫自己的表,像在0.12.0版本

data = [[{:image => "red.png"},{:text => "Red"}], 
     [{:image => "blue.png"},{:text => "Blue"}]] 
data.each_with_index do |row,i| 
    row.each_with_index do |cell,j| 
    bounding_box [x_pos,y_pos], :width => cell_width, :height => cell_height do 
     image(cell[:image], ...) if cell[:image].present? 
     text_box(cell[:text], ...) if cell[:text].present? 
    end 
    x_pos = (x_pos + cell_width) 
    end 
    y_pos = (y_pos - cell_height) 
end 
4

蝦不給在單元格中插入圖像的可能性。看看這個further information。它適用於下一個版本1.0.0.rc1。只需更改您的版本。你也可以使用棘手的方式,但我建議你不要這麼做。 該手冊可用here

作者對該功能的提交和解釋。 Here