私は宝石cを作成これを達成するためにalled pdf_ravager
。これは基本的にmperham found(そしてJRubyに依存している)というアプローチを使用しますが、XFAフォーム(Adobe LiveCycleから作成されたXMLベースのフォーム)を処理する能力も強化されています。私はまた、プロセスをより読みやすくする本当にシンプルなDSLを作成しました。
require 'pdf_ravager'
data = {:name => 'Bob', :gender => 'm', :relation => 'Uncle' }
info = pdf do
text 'name', data[:name]
text 'name_stylized', "<b>#{data[:name]}</b>", :rich => true
radio_group 'sex' do
fill 'male' if data[:gender] == 'm'
fill 'female' if data[:gender] == 'f'
end
check 'related' if data[:relation]
checkbox_group 'relation' do
case data[:relation]
when 'Mom', 'Dad'
check 'parent'
when 'Brother', 'Sister'
check 'sibling'
else
check 'other'
end
end
end
info.ravage '/tmp/info.pdf', :out_file => '/tmp/info_filled.pdf'
# if you'd like the populated form to be read-only:
info.ravage '/tmp/info.pdf', :out_file => '/tmp/info_filled.pdf', :read_only => true
それはまだ非常に若いですが、それは今のシンプルなフォームのために働く必要があります。次に例を示します。私はそれを締めて、すぐにもっと多くの機能を追加したいと思っています。フィードバック/プルのリクエストは大歓迎です!
http://stackoverflow.com/questions/433136/generate-pdf-from-rails – crazycrv