PHPackages                             henck/rtf-to-html - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. henck/rtf-to-html

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

henck/rtf-to-html
=================

RTF to HTML converter in PHP

1.3(3mo ago)109837.5k↓50.4%80[22 issues](https://github.com/henck/rtf-html-php/issues)[4 PRs](https://github.com/henck/rtf-html-php/pulls)1MITPHPCI passing

Since Jun 10Pushed 1mo ago9 watchersCompare

[ Source](https://github.com/henck/rtf-html-php)[ Packagist](https://packagist.org/packages/henck/rtf-to-html)[ RSS](/packages/henck-rtf-to-html/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (2)Versions (7)Used By (1)

rtf-html-php
============

[](#rtf-html-php)

*An RTF to HTML converter in PHP*

In a recent project, I desperately needed an RTF to HTML converter written in PHP. Googling around turned up some matches, but I could not get them to work properly. Also, one of them called `passthru()` to use a RTF2HTML executable, which is something I didn’t want. I was looking for an RTF to HTML converter written purely in PHP.

Since I couldn’t find anything ready-made, I sat down and coded one up myself. It’s short, and it works, implementing the subset of RTF tags that you’ll need in HTML and ignoring the rest. As it turns out, the RTF format isn’t that complicated when you really look at it, but it isn’t something you code a parser for in 15 minutes either.

How to use it
-------------

[](#how-to-use-it)

Install this package using composer. Then do this:

```
use RtfHtmlPhp\Document;

$rtf = file_get_contents("test.rtf");
$document = new Document($rtf); // or use a string directly
```

`Document` will raise an exception if the RTF document could not be parsed. Parse errors will generate PHP notices.

If you’d like to see what the parser read (for debug purposes), then call this:

```
echo $document;
```

To convert the parser’s parse tree to HTML, call this (but only if the RTF was successfully parsed):

```
use RtfHtmlPhp\Html\HtmlFormatter;
$formatter = new HtmlFormatter();
echo $formatter->Format($document);
```

For enhanced compatibility the default character encoding of the converted RTF unicode characters is set to `HTML-ENTITIES`. To change the default encoding, you can initialize the `Html` object with the desired encoding supported by `mb_list_encodings()`: ex. `UTF-8`

```
$formatter = new HtmlFormatter('UTF-8');
```

Install via Composer
--------------------

[](#install-via-composer)

```
composer require henck/rtf-to-html
```

Caveats
-------

[](#caveats)

- Please note that rtf-html-php requires your PHP installation to support the `mb_convert_encoding` function. Therefore you must have the `php-mbstring` module installed. For fresh PHP installations, it will usually be there.

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~821 days

Total

4

Last Release

91d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6217994?v=4)[Brett B](/maintainers/bretto36)[@bretto36](https://github.com/bretto36)

![](https://www.gravatar.com/avatar/c7721e8962886edb5508d6d6069884b57f95f0fec23b1f19917553784bd96d26?d=identicon)[henck](/maintainers/henck)

---

Top Contributors

[![henck](https://avatars.githubusercontent.com/u/10880501?v=4)](https://github.com/henck "henck (70 commits)")[![sipryan](https://avatars.githubusercontent.com/u/32551786?v=4)](https://github.com/sipryan "sipryan (43 commits)")[![rafaelapuka](https://avatars.githubusercontent.com/u/21339687?v=4)](https://github.com/rafaelapuka "rafaelapuka (9 commits)")[![hc0503](https://avatars.githubusercontent.com/u/54434088?v=4)](https://github.com/hc0503 "hc0503 (3 commits)")[![zonuexe](https://avatars.githubusercontent.com/u/822086?v=4)](https://github.com/zonuexe "zonuexe (2 commits)")[![cyrosy](https://avatars.githubusercontent.com/u/2836107?v=4)](https://github.com/cyrosy "cyrosy (2 commits)")[![bnd170](https://avatars.githubusercontent.com/u/5690663?v=4)](https://github.com/bnd170 "bnd170 (2 commits)")[![harlong](https://avatars.githubusercontent.com/u/116577111?v=4)](https://github.com/harlong "harlong (2 commits)")[![Leshana](https://avatars.githubusercontent.com/u/14110581?v=4)](https://github.com/Leshana "Leshana (1 commits)")[![livkiss](https://avatars.githubusercontent.com/u/256075?v=4)](https://github.com/livkiss "livkiss (1 commits)")[![lm-cmxkonzepte](https://avatars.githubusercontent.com/u/45796141?v=4)](https://github.com/lm-cmxkonzepte "lm-cmxkonzepte (1 commits)")[![RsAalund](https://avatars.githubusercontent.com/u/71169600?v=4)](https://github.com/RsAalund "RsAalund (1 commits)")[![vmrfriz](https://avatars.githubusercontent.com/u/25864985?v=4)](https://github.com/vmrfriz "vmrfriz (1 commits)")[![itsieber](https://avatars.githubusercontent.com/u/20435788?v=4)](https://github.com/itsieber "itsieber (1 commits)")[![bretto36](https://avatars.githubusercontent.com/u/6217994?v=4)](https://github.com/bretto36 "bretto36 (1 commits)")[![datashaman](https://avatars.githubusercontent.com/u/59514?v=4)](https://github.com/datashaman "datashaman (1 commits)")[![elvis-epx](https://avatars.githubusercontent.com/u/5000832?v=4)](https://github.com/elvis-epx "elvis-epx (1 commits)")[![Fosnez](https://avatars.githubusercontent.com/u/8691414?v=4)](https://github.com/Fosnez "Fosnez (1 commits)")[![alessandrobelli](https://avatars.githubusercontent.com/u/3796324?v=4)](https://github.com/alessandrobelli "alessandrobelli (1 commits)")[![JuliusPC](https://avatars.githubusercontent.com/u/15018932?v=4)](https://github.com/JuliusPC "JuliusPC (1 commits)")

---

Tags

converterphprtfconverterrtf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/henck-rtf-to-html/health.svg)

```
[![Health](https://phpackages.com/badges/henck-rtf-to-html/health.svg)](https://phpackages.com/packages/henck-rtf-to-html)
```

###  Alternatives

[mark-gerarts/auto-mapper-plus

An AutoMapper for PHP

5623.4M22](/packages/mark-gerarts-auto-mapper-plus)[iamcal/php-emoji

This is a PHP library for dealing with Emoji, allowing you to convert between various native formats and displaying them using HTML.

1.3k528.3k](/packages/iamcal-php-emoji)[matthiasmullie/path-converter

Relative path converter

10231.2M8](/packages/matthiasmullie-path-converter)[ncjoes/office-converter

PHP Wrapper for LibreOffice

2521.3M4](/packages/ncjoes-office-converter)[magyarandras/amp-converter

A library to convert HTML articles, blog posts or similar content to AMP (Accelerated Mobile Pages).

65154.1k](/packages/magyarandras-amp-converter)[nizsheanez/yii2-asset-converter

Less, Sass, Scss and Phamlp converter for Yii2. No system requires. yii2-composer support, Less autoupdate, customizing of output directory

61169.7k6](/packages/nizsheanez-yii2-asset-converter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
