Click here to Skip to main content
14,177,020 members
Click here to Skip to main content
Add your own
alternative version


84 bookmarked
Posted 3 Jun 2005
Licenced CPOL

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

GeneralRe: cells display trleft0 Pin
Mei You Qian20-Jul-06 0:45
professionalMei You Qian20-Jul-06 0:45 
GeneralRe: cells display trleft0 Pin
dankomil13-Aug-06 13:19
memberdankomil13-Aug-06 13:19 
GeneralRe: cells display trleft0 Pin
Mei You Qian6-Nov-06 1:30
professionalMei You Qian6-Nov-06 1:30 
GeneralBig error Pin
h_Danaei6-Dec-05 3:02
memberh_Danaei6-Dec-05 3:02 
GeneralCrash memeory- please help Pin
h_Danaei5-Dec-05 20:55
memberh_Danaei5-Dec-05 20:55 
QuestionSmall bug? Pin
Member 100056321-Sep-05 7:35
memberMember 100056321-Sep-05 7:35 
QuestionNot support Unicode? Pin
Member 15576081-Sep-05 0:33
memberMember 15576081-Sep-05 0:33 
AnswerRe: Not support Unicode? Pin
andrewtruckle19-Mar-08 4:10
memberandrewtruckle19-Mar-08 4:10 
As it stands it is not unicode aware. All of the function calls are char* and the header has the code page hardcoded to 1252.

It would have to be modified to be unicode aware for other language support. But since the author has not replied to you in 3 years, I doubt he will reply to me either. Sigh | :sigh:


PS. But thank you for providding the library - it is a great concept - if only unicode aware
GeneralRTF Lib for C# users Pin
eLToBiS21-Jul-05 12:02
membereLToBiS21-Jul-05 12:02 
GeneralMemory Leaks Pin 17:47 17:47 
GeneralRe: Memory Leaks Pin 3:38 3:38 
SuggestionRe: Memory Leaks Pin
chenlilming31-Jul-12 21:49
memberchenlilming31-Jul-12 21:49 
GeneralHeaders / footer / page number Pin
LotharLinux10-Jun-05 4:27
memberLotharLinux10-Jun-05 4:27 
GeneralRe: Headers / footer / page number Pin
LotharLinux10-Jun-05 4:50
memberLotharLinux10-Jun-05 4:50 
GeneralRe: Headers / footer / page number Pin
Anonymous10-Jun-05 8:37
memberAnonymous10-Jun-05 8:37 
GeneralRTF file and jpeg's Pin
8-Jun-05 3:18
suss8-Jun-05 3:18 
GeneralRe: RTF file and jpeg's Pin
darkoman10-Jun-05 4:21
memberdarkoman10-Jun-05 4:21 
GeneralSample crashed. Pin
WREY4-Jun-05 12:43
memberWREY4-Jun-05 12:43 
GeneralRe: Sample crashed. Pin
Anonymous4-Jun-05 21:49
memberAnonymous4-Jun-05 21:49 
Generalgood job, but problem using table Pin
ziyoo3-Jun-05 20:03
memberziyoo3-Jun-05 20:03 
GeneralRe: good job, but problem using table Pin
Anonymous3-Jun-05 21:34
memberAnonymous3-Jun-05 21:34 
GeneralGreat!!,This is a good starting for all developers! Pin
ucc8013-Jun-05 5:44
memberucc8013-Jun-05 5:44 

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 | Cookies | Terms of Use | Mobile
Web01 | 2.8.190526.1 | Last Updated 6 Jun 2005
Article Copyright 2005 by darkoman
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid