Converts RTF documents to HTML. It features two engines that performs a bit differently, so you might try both on your RTF data.
By default the only prerequisite is to install Python. Then install this module:
npm install unrtf
var unrtf = require('unrtf');
unrtf(
'{\\rtf1\\ansi\\ansicpg1252\\cocoartf1265\\cocoasubrtf210\n{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}\n{\\colortbl;\\red255\\green255\\blue255;}\n\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww10800\\viewh8400\\viewkind0\n\\pard\\tx566\\tx1133\\tx1700\\tx2267\\tx2834\\tx3401\\tx3968\\tx4535\\tx5102\\tx5669\\tx6236\\tx6803\\pardirnatural\n\n\\f0\\fs24 \\cf0 Hello, World!\\\n\\\nThis is RTF. :-)}',
function(error, result) {
console.log(result.html);
}
);
unrtf(doc, [options], callback)
Type: string (required)
The input RTF document you want to convert.
Type: object (optional)
Three options are supported:
- engine, choose the RTF converter engine, either "pyth" (default) or "unrtf"
- unclean, if set to true it will not try to clean up the resulting HTML code, only applies to
unrtf
engine (default false) - timeout, set the timeout of calling the
unrtf
command in milliseconds (default 2000)
Type: function (required)
Invoked with the result or error, if any.
You can choose between two engines:
- "pyth" (default), depends on Python being installed on your system
- "unrtf", depends on a command line utility
If you want to use the unrtf engine, you need to first install the utility:
- Mac:
brew install unrtf
- Ubuntu:
aptitude install unrtf
- Windows: find the Windows installer here
You can set the default engine:
var unrtf = require('unrtf');
unrtf.defaultEngine = 'unrtf';
The code for node-unrtf is licensed under the MIT license. See license.txt
file for more info.