PHPackages                             clank-ai/rtf-converter - 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. clank-ai/rtf-converter

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

clank-ai/rtf-converter
======================

A simple RTF to Plain Text Converter using regular expressions. Support for PHP, Python, Javascript and CSharp

v0.1.22(2y ago)54.8k↑1457.1%2[1 issues](https://github.com/ClankDev/RTF-Converter/issues)[1 PRs](https://github.com/ClankDev/RTF-Converter/pulls)MITC++PHP &gt;=7.0

Since Aug 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ClankDev/RTF-Converter)[ Packagist](https://packagist.org/packages/clank-ai/rtf-converter)[ RSS](/packages/clank-ai-rtf-converter/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

 Python, Javascript, PHP and C-Sharp RTF-Converter
 RTF-Converter is a function that allows users to convert Rich Text Format (RTF) files into plain text using regular expressions.

 [![](/sample-rtf.PNG)](/sample-rtf.PNG)

Features:

Lightweight
Fast and efficient
Pure code, no external dependencies

**Installation**

***Clone the repository:***
git clone
cd RTF-Converter

***Install using pip:***
pip install rtf-converter

***Install using npm:***
npm i rtf-converter

***Install using composer:***
composer require clank-ai/rtf-converter

**Python - Example Usage**

*Convert a simple RTF string to plain text:*

-------------------------------------------------------------------------

[](#python---example-usageconvert-a-simple-rtf-string-to-plain-text)

```
from rtf_converter import rtf_to_txt

# Sample RTF text
rtf_text = r"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Helvetica;}}{\colortbl ;\red255\green0\blue0;}\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural\f0\fs24 \cf0 Hello, World!}"

# Convert RTF to plain text
plain_text = rtf_to_txt(rtf_text)
print(plain_text)  # Output: Hello, World!

```

---

**Python - Example Usage #2**

*Convert an RTF File to Plain Text*
*Read file from the disk, convert its content to plain text using the rtf\_to\_txt function, and then save the result to a new text file:*

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#python---example-usage-2convert-an-rtf-file-to-plain-textread-file-from-the-disk-convert-its-content-to-plain-text-using-the-rtf_to_txt-function-and-then-save-the-result-to-a-new-text-file)

```
from rtf_converter import rtf_to_txt

# Read RTF file
with open('sample.rtf', 'r', encoding='utf-8') as file:
    rtf_content = file.read()

# Convert RTF content to plain text
plain_text = rtf_to_txt(rtf_content)

# Save plain text to a new file
with open('output.txt', 'w', encoding='utf-8') as file:
    file.write(plain_text)

print("RTF has been successfully converted to plain text and saved as output.txt.")

```

---

**Python - Handling RTF Conversion Errors**

*In case the RTF content is not formatted correctly, the rtf\_to\_txt function might raise an exception. Here is how you can handle such errors gracefully:*

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#python---handling-rtf-conversion-errorsin-case-the-rtf-content-is-not-formatted-correctly-the-rtf_to_txt-function-might-raise-an-exception-here-is-how-you-can-handle-such-errors-gracefully)

```
from rtf_converter import rtf_to_txt

# Sample RTF text (potentially incorrect format)
rtf_text = r"{\rtf1\ansi\Hello, World!}"

# Attempt to convert RTF to plain text
try:
    plain_text = rtf_to_txt(rtf_text)
    print(plain_text)
except Exception as e:
    print("An error occurred during the conversion:", str(e))

```

---

**JavaScript - Example Usage**

*Convert a simple RTF string to plain text:*

-----------------------------------------------------------------------------

[](#javascript---example-usageconvert-a-simple-rtf-string-to-plain-text)

```
// Start test server (http-server)
// Save test javascript file as a module (.mjs)
// Import the rtfToTxt function from the rtf-converter npm package
import { rtfToTxt } from './node_modules/rtf-converter/rtf_converter.js';

// Sample RTF text
var rtfText = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Helvetica;}}{\\colortbl ;\\red255\\green0\\blue0;}\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural\\f0\\fs24 \\cf0 Hello, World!}";

// Convert RTF to plain text
var plainText = rtfToTxt(rtfText);
console.log(plainText);  // Output: Hello, World!

```

---

**JavaScript - Example Usage #2 (With error handling)**

*Convert an RTF File to Plain Text*
*Read file from the disk (or fetch from a server), convert its content to plain text using the rtfToTxt function, and then save the result to a new text file:*

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#javascript---example-usage-2-with-error-handlingconvert-an-rtf-file-to-plain-textread-file-from-the-disk-or-fetch-from-a-server-convert-its-content-to-plain-text-using-the-rtftotxt-function-and-then-save-the-result-to-a-new-text-file)

```

    RTF Converter

    RTF Converter

    Convert RTF to Text

// Import the rtfToTxt function from the rtf-converter npm package
import { rtfToTxt } from './node_modules/rtf-converter/rtf_converter.js';

// Function to handle the conversion process
function convertRTF() {
    var fileInput = document.getElementById('rtfFile');
    var file = fileInput.files[0];
    if (!file) {
    alert('Please select an RTF file to convert.');
    return;
    }

    // Read the RTF content from the uploaded file
    var reader = new FileReader();
    reader.onload = function(event) {
    var rtfContent = event.target.result;

    // Convert RTF content to plain text using the rtfToTxt function
    var plainText = rtfToTxt(rtfContent);

    // Save plain text to a new file
    var blob = new Blob([plainText], { type: 'text/plain' });
    var link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = 'output.txt';
    link.click();

    console.log("RTF has been successfully converted to plain text and saved as output.txt.");
    };
    reader.readAsText(file);
}

// Make the convertRTF function globally accessible so that it can be called from the HTML file
window.convertRTF = convertRTF;

```

---

**PHP - Example Usage**

*Convert a simple RTF string to plain text:*

----------------------------------------------------------------------

[](#php---example-usageconvert-a-simple-rtf-string-to-plain-text)

```

```

---

**PHP - Handling RTF Conversion Errors**

*In case the RTF content is not formatted correctly, the rtfToTxt function might raise an exception. Here is how you can handle such errors gracefully:*

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#php---handling-rtf-conversion-errorsin-case-the-rtf-content-is-not-formatted-correctly-the-rtftotxt-function-might-raise-an-exception-here-is-how-you-can-handle-such-errors-gracefully)

```

```

---

**C++ - Example Usage**

*Convert a simple RTF string to plain text:*

----------------------------------------------------------------------

[](#c---example-usageconvert-a-simple-rtf-string-to-plain-text)

```
#include &lt;iostream&gt;
#include &lt;string&gt;
#include "rtf_converter.cpp" // Assume this header contains the declaration of rtf_to_txt function

int main() {
    // Sample RTF text
    std::string rtfText = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Helvetica;}}{\\colortbl ;\\red255\\green0\\blue0;}\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural\\f0\\fs24 \\cf0 Hello, World!}";

    // Convert RTF to plain text
    std::string plainText = rtf_to_txt(rtfText);

    std::cout &lt;&lt; plainText;  // Output: Hello, World!

    return 0;
}

```

---

**C++ - Example Usage #2**

*Convert an RTF File to Plain Text*
*Read file from the disk, convert its content to plain text using the rtf\_to\_txt function, and then save the result to a new text file:*

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#c---example-usage-2convert-an-rtf-file-to-plain-textread-file-from-the-disk-convert-its-content-to-plain-text-using-the-rtf_to_txt-function-and-then-save-the-result-to-a-new-text-file)

```
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include "rtf_converter.cpp" // Assume this header contains the declaration of rtf_to_txt function

int main() {
    // Read RTF file
    std::ifstream rtfFile("sample.rtf");
    std::string rtfContent((std::istreambuf_iterator&lt;char&gt;(rtfFile)), std::istreambuf_iterator&lt;char&gt;());

    // Convert RTF content to plain text
    std::string plainText = rtf_to_txt(rtfContent);

    // Save plain text to a new file
    std::ofstream outFile("output.txt");
    outFile &lt;&lt; plainText;

    std::cout &lt;&lt; "RTF has been successfully converted to plain text and saved as output.txt." &lt;&lt; std::endl;

    return 0;
}

```

---

**C++ - Handling RTF Conversion Errors**

*In case the RTF content is not formatted correctly, the rtf\_to\_txt function might throw an exception. Here is how you can handle such errors gracefully:*

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#c---handling-rtf-conversion-errorsin-case-the-rtf-content-is-not-formatted-correctly-the-rtf_to_txt-function-might-throw-an-exception-here-is-how-you-can-handle-such-errors-gracefully)

```
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;exception&gt;
#include "rtf_converter.cpp" // Assume this header contains the declaration of rtf_to_txt function

int main() {
    // Sample RTF text (potentially incorrect format)
    std::string rtfText = "{\\rtf1\\ansi\\Hello, World!}";

    // Attempt to convert RTF to plain text
    try {
        std::string plainText = rtf_to_txt(rtfText);
        std::cout &lt;&lt; plainText;
    } catch (const std::exception&amp; e) {
        std::cout &lt;&lt; "An error occurred during the conversion: " &lt;&lt; e.what() &lt;&lt; std::endl;
    }

    return 0;
}

```

---

**Contributing**
Contributions, issues, and feature requests are welcome!

**License**
This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~0 days

Total

2

Last Release

1047d ago

### Community

Maintainers

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

---

Top Contributors

[![ClankDev](https://avatars.githubusercontent.com/u/130015630?v=4)](https://github.com/ClankDev "ClankDev (76 commits)")

---

Tags

convertercsharpjavascriptphppythonrtfrtf-converterrtf-to-text

### Embed Badge

![Health badge](/badges/clank-ai-rtf-converter/health.svg)

```
[![Health](https://phpackages.com/badges/clank-ai-rtf-converter/health.svg)](https://phpackages.com/packages/clank-ai-rtf-converter)
```

###  Alternatives

[h4kuna/ares

Provides information about subjects by their identification number from the ARES database (in Czech Republic).

50419.6k2](/packages/h4kuna-ares)

PHPackages © 2026

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