gpt4 book ai didi

ruby-on-rails-3 - 在 Rails 3.2 中生成 rtf 文档

转载 作者:行者123 更新时间:2023-12-04 07:16:39 25 4
gpt4 key购买 nike

我是 Rails 新手。有人可以告诉我是否有一种快速简便的方法来生成 rtf 文档供人们使用 rails 下载?例如,如果我有“views/users/show.html.erb”,则 View 通常会输出为 html,所以我希望人们能够下载为相同的 rtf 文档?

最佳答案

ruby-rtf是您正在寻找的 gem 。有一些rtf生成的例子here

将此添加到初始化程序/mime_types.rb:

Mime::Type.register "text/richtext", :rtf

代码给你一个想法:

document = RTF::Document.new(RTF::Font.new(RTF::Font::ROMAN, 'Times New Roman'))
document.paragraph do |p|
p << "This is the first sentence in the paragraph. "
p << "This is the second sentence in the paragraph. "
p << "And this is the third sentence in the paragraph."
end

send_file document, :type=>"text/richtext"

关于ruby-on-rails-3 - 在 Rails 3.2 中生成 rtf 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9539725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com