Click here to Skip to main content
Licence 
First Posted 3 Jun 2005
Views 99,786
Bookmarked 64 times

rtflib v1.0

By | 5 Jun 2005 | Article
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

darkoman

Software Developer (Senior)
Elektromehanika d.o.o. Nis
Serbia Serbia

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 PinmemberK4HVDs8:52 30 Mar '12  
GeneralHow to merge two rtf files ? PinmemberKoma Wang20:01 12 Apr '11  
QuestionTable width and paper width Pinmembernaghekyan4:19 9 Jul '10  
GeneralI modified a copy to support the Chinese language Pinmemberzyj4023015:40 26 Apr '10  
GeneralRe: I modified a copy to support the Chinese language Pingrouptianyige072615:47 25 Aug '10  
GeneralUnicode patch Pinmembermargaritaville15:18 17 Sep '09  
GeneralRe: Unicode patch Pinmember_EOA_7:29 26 Dec '10  
Generalint rtf_start_tablerow() corrupts the stack Pinmembermhorowit15:30 15 Mar '09  
QuestionWill this library work for creating non-english RTF content? Pinmemberandrewtruckle3:23 19 Mar '08  
AnswerRe: Will this library work for creating non-english RTF content? Pinmemberzyj4023015:33 26 Apr '10  
Generalrtf_load_image memory leak PinmemberCopyMaster0:17 11 Jan '08  
Generalrtf_write_paragraphformat Pinmemberhenk21cm5:28 6 Jan '08  
GeneralSuggested Enhacement to Image Loading PinmemberAbbas Ibn Fernas23:03 18 Nov '07  
QuestionLandscape? Pinmembers.jb6:42 7 Sep '07  
Questioni want to know some about jpg in rtf, thanks for share Pinmemberikohl15:46 28 Jun '07  
NewsGreat! Pinmembersleet17:44 31 Mar '07  
QuestionHow to link to the header from a template ? PinmemberStefan Georgescu21:16 31 Jan '07  
GeneralUnicode Pinmemberdankomil11:14 10 Oct '06  
GeneralRe: Unicode Pinmemberandrewtruckle4:08 19 Mar '08  
GeneralRe: Unicode PinmemberHiHand5:21 11 Aug '11  
GeneralBugs fixed Pinmembermrsilver10:47 6 Oct '06  
Generalcells display trleft0 PinmemberMei You Qian0:33 20 Jul '06  
GeneralRe: cells display trleft0 PinmemberMei You Qian0:45 20 Jul '06  
GeneralRe: cells display trleft0 Pinmemberdankomil13:19 13 Aug '06  
GeneralRe: cells display trleft0 PinmemberMei You Qian1:30 6 Nov '06  

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.

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