Click here to Skip to main content
15,881,803 members
Articles / Desktop Programming / MFC
Article

rtflib v1.0

Rate me:
Please Sign up or sign in to vote.
3.81/5 (41 votes)
5 Jun 2005CPOL2 min read 418.1K   10.9K   84   52
An article on extending applications with export to Rich Text Formatted documents.

Sample Image

Introduction

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.

Background

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.

History

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

License

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


Written By
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.

Comments and Discussions

 
GeneralUnicode Pin
dankomil10-Oct-06 11:14
dankomil10-Oct-06 11:14 
GeneralRe: Unicode Pin
andrewtruckle19-Mar-08 4:08
andrewtruckle19-Mar-08 4:08 
GeneralRe: Unicode Pin
HiHand11-Aug-11 5:21
HiHand11-Aug-11 5:21 
GeneralBugs fixed Pin
mrsilver6-Oct-06 10:47
mrsilver6-Oct-06 10:47 
Generalcells display trleft0 Pin
Mei You Qian20-Jul-06 0:33
professionalMei You Qian20-Jul-06 0:33 
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
dankomil13-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
h_Danaei6-Dec-05 3:02 
GeneralCrash memeory- please help Pin
h_Danaei5-Dec-05 20:55
h_Danaei5-Dec-05 20:55 
QuestionSmall bug? Pin
Member 100056321-Sep-05 7:35
Member 100056321-Sep-05 7:35 
QuestionNot support Unicode? Pin
Member 15576081-Sep-05 0:33
Member 15576081-Sep-05 0:33 
AnswerRe: Not support Unicode? Pin
andrewtruckle19-Mar-08 4:10
andrewtruckle19-Mar-08 4:10 
GeneralRTF Lib for C# users Pin
eLToBiS21-Jul-05 12:02
eLToBiS21-Jul-05 12:02 
GeneralMemory Leaks Pin
lperalta@cable.net.co17-Jul-05 17:47
lperalta@cable.net.co17-Jul-05 17:47 
GeneralRe: Memory Leaks Pin
lperalta@cable.net.co18-Jul-05 3:38
lperalta@cable.net.co18-Jul-05 3:38 
SuggestionRe: Memory Leaks Pin
chenlilming31-Jul-12 21:49
chenlilming31-Jul-12 21:49 
GeneralHeaders / footer / page number Pin
LotharLinux10-Jun-05 4:27
LotharLinux10-Jun-05 4:27 
GeneralRe: Headers / footer / page number Pin
LotharLinux10-Jun-05 4:50
LotharLinux10-Jun-05 4:50 
GeneralRe: Headers / footer / page number Pin
Anonymous10-Jun-05 8:37
Anonymous10-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
darkoman10-Jun-05 4:21 
GeneralSample crashed. Pin
WREY4-Jun-05 12:43
WREY4-Jun-05 12:43 
GeneralRe: Sample crashed. Pin
Anonymous4-Jun-05 21:49
Anonymous4-Jun-05 21:49 
Generalgood job, but problem using table Pin
ziyoo3-Jun-05 20:03
ziyoo3-Jun-05 20:03 

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.