新手问题 How to convert RTF file to HTML?

bruceyue · 2013年12月16日 · 最后由 bruceyue 回复于 2013年12月23日 · 2374 次阅读

Dear 各位大神

我有一个 rtf 的文件,想把他转化为 html 的。用 ruby 怎么实现呢?

谢谢

简单方法:调外部命令 unrtf 或者 pandoc 或者用 https://github.com/clbustos/rtf

@luikore 你说的这个包具体怎么用呢?有没有类似 rtf.to_html 的方法?

pandoc 不支持 rtf 吧?

require 'pandoc-ruby'  

rtf_str = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\f0\fs17 Received Billing Agreement 12 04 12 KC \par Number of properties - 40\par \par \ul\b ***VERIFY WITH JOHN IF THE PROPERTY HE IS CALLING IN IS A FANNIE MAE OR NOT***\par \par \par 1) On Vacant Fannie Mae properties ABC Company to fannie mae key- \par 2) On occupied properties ABC Company to random key \par 3) NON-FANNIE MAE PROPERTIES - KEY TO 60-70 and L-S\ulnone\b0\par \ul\b 4)\ulnone\b0 . Leave 2 keys at property\par 5). Do not test smoke alarms/only test on a per request basic\par 6) Always remove double cylinder deadbolts and replace with single cylinder deadbolts\par 7). Locking Knobs- other- Check if locking knobs need to be ABC Companyed and who has access (?)\par 8). Do not install security bar\par 9). Only ABC Company overhead garage doors when specifically requested \par 10). JOBS NOT TO EXCEEED $150 or Call if it goes over\par 11) Per John DO NOT LEAVE ANY KEYS FOR FANNIE MAE PROPERTIES EVER< UNLESS INSTRUCTED \par \par \par \ul\b OFFICE:\par \par \ulnone\b0 1. Leave 2 keys at property\par 2. Email invoice IMMEDIATELY ON COMPLETION OF JOB!!!\par \par \par \ul\b AUTHORIZED TO USE ACCOUNT:\par \par \pard\ulnone\b0 1. John Nold 425-777-0639\fs17 }"  

puts PandocRuby.convert(rtf_str, :from => rtf, :to => :html)  

报错

需要 登录 后方可回复, 如果你还没有账号请 注册新账号