Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read (and write) RTF files with C++ / Qt [closed]

Tags:

c++

parsing

qt

rtf

I am looking for a simple C++ library for tokenizing and parsing RTF (Rich Text Format) files. I am planning to edit them with Qt's QTextEdit.

More the Formatting preserved the better -- but actually I am planning to use Bold and Italics only.

In perl I would use RTF::Tokenizer.

It would be nice if the module had some sort of interface for writing also, but I am able to brute force that with a template and some regular expressions.

like image 678
user38075 Avatar asked Nov 16 '08 20:11

user38075


People also ask

Can Linux read RTF files?

Many Linux distributions include an office suite like LibreOffice that can open RTF files. If yours doesn't, you can install it through the command line or go to https://www.libreoffice.org/ to download the package directly. Also, most online word processors can open RTF files.

Is RTF open source?

OpenRTF is a Java library for creating and editing RTF (Rich Text Format) files with a LGPL and MPL open source license. We welcome contributions from other developers.

Is RTF cross-platform?

RTF file is a cross-platform document format that stands for "rich text format." These documents can save additional information about text styles, fonts, images and formatting while normal text files save only plain text. Most word processing applications can save and open these types of documents.

Is RTF format editable?

The primary advantage of using RTF is that it is a cross-platform format. This means that you can open and edit RTF files on any word processor that supports the format.


3 Answers

I helped writing the RTF import export filter in KOffice. You can have a look at the code at https://cgit.kde.org/koffice.git/tree/filters/kword/rtf. The code is modular and it depends only on Qt.

like image 162
Ariya Hidayat Avatar answered Oct 30 '22 23:10

Ariya Hidayat


A quick SourceForge search suggests librtf. It hasn't been developed in a while, but is listed as stable and is under the LGPL. I don't know whether it will support what you need, but I always suggest searching SourceForge for libraries.

like image 31
coppro Avatar answered Oct 30 '22 23:10

coppro


You can ask the #koffice guys on irc.freenode.org over irc. Their program kword is able to open RTF files, and is indeed also written in Qt. I'm sure they would be glad to tell you about how they do it.

like image 2
Johannes Schaub - litb Avatar answered Oct 30 '22 23:10

Johannes Schaub - litb