Click here to Skip to main content
13,401,629 members (51,629 online)
Click here to Skip to main content
Add your own
alternative version


81 bookmarked
Posted 3 Jun 2005

rtflib v1.0

, 5 Jun 2005
Rate this:
Please Sign up or sign in to vote.
An article on extending applications with export to Rich Text Formatted documents.

Sample Image


This article is about generating RTF documents from the source code. For this purpose, a free C-library is developed in order to help developers. Considering this release, 100% compatibility is achieved only with MS Word 97 to MS Word 2003 applications used as external RTF viewer to generated RTF documents. For the future, it is planned to extend this to all possible RTF viewers that support RTF specification 1.8 which is documented by Microsoft and can be found here.


A developer may use CRichEditCtrl, a MFC control, in order to get RTF output from the source code. This is the control upon which WordPad application is built. But, there are many limitations when considering the generated RTF file. Also, an RTF document can be created with any advanced text editor directly. This library, however, provides a low-level interface to RTF syntax which is not so easy to be hand-coded like HTML. It can be extended and adopted to custom needs. Also, a custom high-level interface is a challenge to be built on this low-level interface base.

Using the code

A full description of using the library code is provided in a separate guide (can be found in the download section above). To use the library in a custom project, include the provided header files (rtflib.h, errors.h, globals.h) and add links in project settings to rtflib.lib compiled module, or download library source and compile it and then include headers and add link to the compiled module. The library source is not hard-tested so memory leaks or some other bugs are possible to be found. If this is the case, please report. But, don't consider wrong output on destination RTF viewer as library error. It is stated here that full compatibility is achieved, for this release, only with MS Word 97 to MS Word 2003 applications.

See an example on using the library below:

// // "HelloWorld" in RTF document example
// Add links to header files (and link to rtflib.lib in project settings)
// #include "rtflib.h"
// #include "errors.h"
// #include "globals.h"
// void main()
// {
//     // RTF document font and color table definition
//     char font_list[] = "Times New Roman;Arial;";
//     char color_list[] = "0;0;0;255;0;0;192;192;192";
//     // Create new RTF document
//     rtf_open( "Sample.rtf", font_list, color_list );
//     // Write simple paragraph text
//     rtf_start_paragraph( "Hello, World !!!", false );
//     // Close RTF document
//     rtf_close();
// }

Points of Interest

I am interested in continuing the work on this library and hope that interested developers will include with their ideas and solutions. A C++ class solution is very simple to be designed on this base. I also plan to write similar PDF generating libraries.


rtflib v1.0 features:

  • document creating and formatting
  • section creating and formatting
  • paragraph creating and formatting
  • character formatting
  • images loading (*.bmp, *.jpg, *.gif)
  • table creating and formatting
  • tabs
  • columns
  • bullets and numbering


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

You may also be interested in...

Comments and Discussions

Questionsource code not updated Pin
songtzu1-Jan-14 20:48
membersongtzu1-Jan-14 20:48 
Questiondoes not support embeded table Pin
songtzu29-Dec-13 19:46
membersongtzu29-Dec-13 19:46 
QuestionLicense for RFTLIB Pin
Paolo Rugarli26-Sep-12 8:27
memberPaolo Rugarli26-Sep-12 8:27 
AnswerRe: License for RFTLIB Pin
darkoman26-Sep-12 10:51
memberdarkoman26-Sep-12 10:51 
GeneralMy vote of 5 Pin
K4HVDs30-Mar-12 9:52
memberK4HVDs30-Mar-12 9:52 
GeneralHow to merge two rtf files ? Pin
Koma Wang12-Apr-11 21:01
memberKoma Wang12-Apr-11 21:01 
QuestionTable width and paper width Pin
naghekyan9-Jul-10 5:19
membernaghekyan9-Jul-10 5:19 
GeneralI modified a copy to support the Chinese language Pin
zyj40230126-Apr-10 6:40
memberzyj40230126-Apr-10 6:40 
GeneralRe: I modified a copy to support the Chinese language Pin
tianyige072625-Aug-10 16:47
grouptianyige072625-Aug-10 16:47 
GeneralRe: I modified a copy to support the Chinese language Pin
chenlilming19-Jul-12 20:49
memberchenlilming19-Jul-12 20:49 
GeneralRe: I modified a copy to support the Chinese language Pin
hainabaichuan12317-Feb-14 3:16
memberhainabaichuan12317-Feb-14 3:16 
GeneralUnicode patch Pin
margaritaville17-Sep-09 16:18
membermargaritaville17-Sep-09 16:18 
GeneralRe: Unicode patch Pin
_EOA_26-Dec-10 8:29
member_EOA_26-Dec-10 8:29 
Generalint rtf_start_tablerow() corrupts the stack Pin
mhorowit15-Mar-09 16:30
membermhorowit15-Mar-09 16:30 
QuestionWill this library work for creating non-english RTF content? Pin
andrewtruckle19-Mar-08 4:23
memberandrewtruckle19-Mar-08 4:23 
AnswerRe: Will this library work for creating non-english RTF content? Pin
zyj40230126-Apr-10 6:33
memberzyj40230126-Apr-10 6:33 
GeneralRe: Will this library work for creating non-english RTF content? Pin
hainabaichuan12316-Feb-14 22:19
memberhainabaichuan12316-Feb-14 22:19 
Generalrtf_load_image memory leak Pin
CopyMaster11-Jan-08 1:17
memberCopyMaster11-Jan-08 1:17 
SuggestionRe: rtf_load_image memory leak Pin
songtzu30-Dec-13 16:22
membersongtzu30-Dec-13 16:22 
Generalrtf_write_paragraphformat Pin
henk21cm6-Jan-08 6:28
memberhenk21cm6-Jan-08 6:28 
GeneralSuggested Enhacement to Image Loading Pin
Abbas Ibn Fernas19-Nov-07 0:03
memberAbbas Ibn Fernas19-Nov-07 0:03 
QuestionLandscape? Pin
s.jb7-Sep-07 7:42
members.jb7-Sep-07 7:42 
Questioni want to know some about jpg in rtf, thanks for share Pin
ikohl28-Jun-07 16:46
memberikohl28-Jun-07 16:46 
NewsGreat! Pin
sleet31-Mar-07 18:44
membersleet31-Mar-07 18:44 
QuestionHow to link to the header from a template ? Pin
Stefan Georgescu31-Jan-07 22:16
memberStefan Georgescu31-Jan-07 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180218.2 | Last Updated 6 Jun 2005
Article Copyright 2005 by darkoman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid