1

私はテーブル内のチケットのリストをオフに印刷しエビのPDFがあります。Prawn PDF表の行全体をどのように叩くのですか?

Prawn::Document.generate("doorlist.pdf") do 
    table([["Ticket", "Name", "Product"]] + tickets.map do |ticket| 
    [ 
    make_cell(:content => ticket.number, :font => "Courier"), 
    make_cell(:content => ticket.holder.full_name), 
    make_cell(:content => ticket.product.name) 
    ] 
    end, :header => true) 
end 

をそして私はticket.has_been_used行を打つしたいのですが?本当です。私はPrawnのドキュメントhttp://prawn.majesticseacreature.com/manual.pdfで、各セルのテキストを:inline_formatオプションで破棄して、Document.generateに貼り付け、"<strikethrough>#{text}</strikethrough>"にテキストをラップすることができますが、行全体をストライクすることは可能ですか?

答えて

2

が、私はこの時行くがあったが、これは私がなってしまったものです:

戦略は、ローごとに新しいテーブルを作成し、垂直方向のセパレータが並ぶように、列のための一定の幅を指定することでした。テーブル(行)を描画した後、私は条件をチェックし、真ならば、セルの高さの半分までカーソルを移動し、ラインを引いてから、元の位置に戻します。

require 'prawn' 
tickets = [ 
    {:number => '123', :name => 'John', :product => 'Foo', :used => true }, 
    {:number => '124', :name => 'Bill', :product => 'Bar', :used => false}, 
    {:number => '125', :name => 'John', :product => 'Baz', :used => true} 
] 

Prawn::Document.generate("doorlist.pdf") do 

    widths = [150,180,200] 
    cell_height = 20 

    table([["Ticket", "Name", "Product"]], :column_widths => widths) 

    tickets.each do |ticket| 

    table([[ 
     make_cell(:content => ticket[:number], :height => cell_height, :font => "Courier"), 
     make_cell(:content => ticket[:name], :height => cell_height, :font => "Courier"), 
     make_cell(:content => ticket[:product], :height => cell_height, :font => "Courier") 
    ]], :column_widths => widths) 

    if ticket[:used] 
     move_up (cell_height/2) 
     stroke_horizontal_rule 
     move_down (cell_height/2) 
    end 

    end 

end 
+0

こんにちは、それはかなり良いですね!一般的にカラム幅は固定されていないのがいいですが、私がやっていることはうまくいきます。 – synecdoche

+1

@synecdocheテーブルを書き出して、固定*高さのセルを使用して、カーソルを正しい位置に移動し、each_with_indexで2回目のデータをループし、どのくらい遠くにカーソルを移動するかを計算しますが、私はあなたのために何がうまくいくかについてあまりにも多くの仮定をしたくありませんでした。 – Unixmonkey

+0

ありがとう、それは私に多くの助けを与える@Unixmonkey – Kashiftufail

関連する問題