Click here to Skip to main content
Click here to Skip to main content
Go to top

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

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)

Share

About the Author

darkoman
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 Pinmembersongtzu1-Jan-14 19:48 
Questiondoes not support embeded table Pinmembersongtzu29-Dec-13 18:46 
QuestionLicense for RFTLIB PinmemberPaolo Rugarli26-Sep-12 7:27 
AnswerRe: License for RFTLIB Pinmemberdarkoman26-Sep-12 9:51 
GeneralMy vote of 5 PinmemberK4HVDs30-Mar-12 8:52 
GeneralHow to merge two rtf files ? PinmemberKoma Wang12-Apr-11 20:01 
QuestionTable width and paper width Pinmembernaghekyan9-Jul-10 4:19 
GeneralI modified a copy to support the Chinese language Pinmemberzyj40230126-Apr-10 5:40 
GeneralRe: I modified a copy to support the Chinese language Pingrouptianyige072625-Aug-10 15:47 
GeneralRe: I modified a copy to support the Chinese language [modified] Pinmemberchenlilming19-Jul-12 19:49 
GeneralRe: I modified a copy to support the Chinese language Pinmemberhainabaichuan12317-Feb-14 2:16 
GeneralUnicode patch Pinmembermargaritaville17-Sep-09 15:18 
GeneralRe: Unicode patch Pinmember_EOA_26-Dec-10 7:29 
Generalint rtf_start_tablerow() corrupts the stack Pinmembermhorowit15-Mar-09 15:30 
QuestionWill this library work for creating non-english RTF content? Pinmemberandrewtruckle19-Mar-08 3:23 
AnswerRe: Will this library work for creating non-english RTF content? Pinmemberzyj40230126-Apr-10 5:33 
GeneralRe: Will this library work for creating non-english RTF content? Pinmemberhainabaichuan12316-Feb-14 21:19 
Generalrtf_load_image memory leak PinmemberCopyMaster11-Jan-08 0:17 
SuggestionRe: rtf_load_image memory leak Pinmembersongtzu30-Dec-13 15:22 
Generalrtf_write_paragraphformat Pinmemberhenk21cm6-Jan-08 5:28 
GeneralSuggested Enhacement to Image Loading PinmemberAbbas Ibn Fernas18-Nov-07 23:03 
QuestionLandscape? Pinmembers.jb7-Sep-07 6:42 
Questioni want to know some about jpg in rtf, thanks for share Pinmemberikohl28-Jun-07 15:46 
NewsGreat! Pinmembersleet31-Mar-07 17:44 
QuestionHow to link to the header from a template ? PinmemberStefan Georgescu31-Jan-07 21:16 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 6 Jun 2005
Article Copyright 2005 by darkoman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid