The RTF Package:
The RTF package is an extension of the iText library and allows iText
to output Rich Text Files in additon to PDF files. These files can then
be viewed and edited with RTF viewers such as Microsoft Word or OpenOffice.org
Writer.
The main class for generating RTF documents is the RtfWriter2.
It supports most of iText's features with the exception of those features listed
under the unsupported features. In addition to this
there are a number of extensions to the core iText classes that provide access
to RTF specific functionality:
Go to top of the page- Extensions to core classes
- RTF specific features
- RTF generation settings
Introduction to RTF:
RTF is the Rich Text Format developed by Microsoft with the aim of providing
a cross-platform text-based document format. The main advantage that it has
over PDF is that it can easily be edited with most word processing software.
Its biggest disadvantage is that it is rendered by the word processing software
when the RTF document is opened and not when the RTF document is generated.
This leads to the situation that the document can look slightly different on
different platforms.
It is important to remember that RTF is a document description format and when iText creates a RTF document, only the description of the document is generated. NO RENDERING TAKES PLACE. It is thus impossible to provide access to such things as page numbers or page events.
Apart from these considerations creating an RTF document works just like creating any other document with iText.
Go to top of the pageIt is important to remember that RTF is a document description format and when iText creates a RTF document, only the description of the document is generated. NO RENDERING TAKES PLACE. It is thus impossible to provide access to such things as page numbers or page events.
Apart from these considerations creating an RTF document works just like creating any other document with iText.
Creating a basic RTF document:
Creating a basic RTF document works just like creating a basic PDF document:
Go to top of the page
Document document = new Document();
RtfWriter2.getInstance(document,
new FileOutputStream("testRTFdocument.rtf"));
document.open();
document.add(new Paragraph("Hello World!"));
document.close();
Example: java
com.lowagie.examples.rtf.HelloWorld
Generates a simple 'Hello World!' RTF file: see HelloWorld.rtf
Extra jars needed in your CLASSPATH: itext-rtf.jar
You can then use the objects described in Using High Level Objects
to create more complex RTF documents.
Generates a simple 'Hello World!' RTF file: see HelloWorld.rtf
Extra jars needed in your CLASSPATH: itext-rtf.jar
Unsupported iText features:
A number of iText features are not supported in the RtfWriter2 due to the fact
that they either have not been implemented or are not supported by the
RTF format itself. The following list may not be complete, since the development
of the RtfWriter2 sometimes lags behind the development of the core library.
Go to top of the page- Images other than JPEG, PNG, BMP, GIF and WMF
- Only these image types are supported natively in the RTF format.
- Rotated images
- Nested tables
- Embedded fonts
- Table.setSpaceInsideCell and Table.setSpaceBetweenCells
- Table.padding
- Watermarks
- Encryption
- Viewer preferences
- These only apply to the Adobe Acrobat Viewer.
- Image borders
- Forms

