Click here to Skip to main content
15,868,340 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 417.6K   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

 
Questionsource code not updated Pin
songtzu1-Jan-14 19:48
songtzu1-Jan-14 19:48 
Questiondoes not support embeded table Pin
songtzu29-Dec-13 18:46
songtzu29-Dec-13 18:46 
QuestionLicense for RFTLIB Pin
Paolo Rugarli26-Sep-12 7:27
Paolo Rugarli26-Sep-12 7:27 
AnswerRe: License for RFTLIB Pin
darkoman26-Sep-12 9:51
darkoman26-Sep-12 9:51 
GeneralMy vote of 5 Pin
K4HVDs30-Mar-12 8:52
K4HVDs30-Mar-12 8:52 
GeneralHow to merge two rtf files ? Pin
wangningyu12-Apr-11 20:01
wangningyu12-Apr-11 20:01 
QuestionTable width and paper width Pin
naghekyan9-Jul-10 4:19
naghekyan9-Jul-10 4:19 
GeneralI modified a copy to support the Chinese language Pin
zyj40230126-Apr-10 5:40
zyj40230126-Apr-10 5:40 
GeneralRe: I modified a copy to support the Chinese language Pin
tianyige072625-Aug-10 15:47
tianyige072625-Aug-10 15:47 
GeneralRe: I modified a copy to support the Chinese language Pin
chenlilming19-Jul-12 19:49
chenlilming19-Jul-12 19:49 
GeneralRe: I modified a copy to support the Chinese language Pin
hainabaichuan12317-Feb-14 2:16
hainabaichuan12317-Feb-14 2:16 
GeneralUnicode patch Pin
margaritaville17-Sep-09 15:18
margaritaville17-Sep-09 15:18 
GeneralRe: Unicode patch Pin
_EOA_26-Dec-10 7:29
_EOA_26-Dec-10 7:29 
Generalint rtf_start_tablerow() corrupts the stack Pin
mhorowit15-Mar-09 15:30
mhorowit15-Mar-09 15:30 
QuestionWill this library work for creating non-english RTF content? Pin
andrewtruckle19-Mar-08 3:23
andrewtruckle19-Mar-08 3:23 
AnswerRe: Will this library work for creating non-english RTF content? Pin
zyj40230126-Apr-10 5:33
zyj40230126-Apr-10 5:33 
GeneralRe: Will this library work for creating non-english RTF content? Pin
hainabaichuan12316-Feb-14 21:19
hainabaichuan12316-Feb-14 21:19 
Generalrtf_load_image memory leak Pin
CopyMaster11-Jan-08 0:17
CopyMaster11-Jan-08 0:17 
SuggestionRe: rtf_load_image memory leak Pin
songtzu30-Dec-13 15:22
songtzu30-Dec-13 15:22 
Generalrtf_write_paragraphformat Pin
henk21cm6-Jan-08 5:28
henk21cm6-Jan-08 5:28 
GeneralSuggested Enhacement to Image Loading Pin
Youssef-Gamal-518-Nov-07 23:03
Youssef-Gamal-518-Nov-07 23:03 
QuestionLandscape? Pin
s.jb7-Sep-07 6:42
s.jb7-Sep-07 6:42 
Questioni want to know some about jpg in rtf, thanks for share Pin
ikohl28-Jun-07 15:46
ikohl28-Jun-07 15:46 
NewsGreat! Pin
sleet31-Mar-07 17:44
sleet31-Mar-07 17:44 
QuestionHow to link to the header from a template ? Pin
Stefan Georgescu31-Jan-07 21:16
Stefan Georgescu31-Jan-07 21: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.