2008-05-11
PDF in Rails
1. install the pdf-writer
2. require & register in the rails env.
3. usage:
# in view
# in browser
gem install pdf-writer
2. require & register in the rails env.
#vi environment.rb require 'pdf/writer' Mime::Type.register 'application/pdf', :pdf
3. usage:
# lib/product_drawer.rb def self.draw(products) pdf = PDF::Writer.new products.each do |product| pdf.text product.name end pdf.render end
# products_controller.rb
def index
@products = Product.find(:all)
respond_to do |format|
format.html
format.pdf do
send_data ProductDrawer.draw(@products),
:filename => 'products.pdf',
:type=> 'application/pdf',
:disposition => 'inline'
end
end
end
# in view
<p><%= link_to 'PDF Format', formatted_products_path(:pdf) %></p>
# in browser
<A href="http://localhost:3000/products.pdf" target=_blank>http://localhost:3000/products.pdf</A>
发表评论
- 浏览: 2499 次
- 性别:

- 来自: 青岛

- 详细资料
搜索本博客
我的相册
android
共 3 张
共 3 张
最近加入圈子
最新评论
-
我收集的电子图书(51leife ...
呵呵
-- by magixyu -
我收集的电子图书(51leife ...
你有的我好像都有,哈哈!
-- by javaeyename -
Advanced Rails - Rails初 ...
-- by yangzhihuan -
Advanced Rails -- Ruby ...
可能是本人水平有限的原因,看了advanced Rails的系列,感觉很难受,很 ...
-- by funseason -
Advanced Rails -- Ruby ...
题目上有,是Oreilly 的 Advanced Rails中的一节,翻译不好, ...
-- by magixyu






评论排行榜