RTF generation settings:
The RtfWriter2 supports a set of configuration switches that can be used to
tailor the RTF generated.
Go to top of the page- outputTableRowDefinitionAfter (Boolean)
- Whether to write the table row definitions both before and after the table data. Set to true if you are generating RTF documents that need to be read with Word 2000. Set to false if you are generating RTF documents that need to be read with OpenOffice.org Writer. By default table row definitions are written both before and after.
- alwaysGenerateSoftLinebreaks (Boolean)
- Whether \n characters should be written as hard or soft linebreaks. By default only \n characters in lists and table cells are written as soft linebreaks. Setting this property to true causes all \n characters to be written as soft linebreaks.s
- alwaysUseUnicode (Boolean)
- Whether all characters bigger than 'z' should be written as unicode escapes or whether the original character should be written. The default is to escape everything, which leads to larger RTF files. Setting this property to false reduces RTF file size, but may lead to characters being displayed incorrectly.
- dataCacheStyle (Integer)
- Specifies where the RTF document is cached during document generation. Valid
values are specified in the RtfDataCache.
- CACHE_MEMORY: The default keeps the whole document in memory. This increases the generation speed, but places a maximum size on the document.
- CACHE_MEMORY_EFFICIENT: The document is kept in memory, but the use of memory is minimised. Depending on how your document is structured, using this might slightly slow down the generation speed, but should reduce the memory footprint by at least 50%.
- Cache_DISK: The document is cached on disk. This decreases the document generation speed, but the maximum document size is increased to the amount of space free on the disk.
- outputDebugLineBreaks (Boolean)
- This setting is primarily for debugging purposes and leads to slightly larger, but more readable RTF files. Set it to false to decrease the RTF file size.
- imagePDFConformance (Boolean)
- This setting controls whether images are scaled so that the result is equivalent to the PDF display. Defaults to true. The result of this is that images are added at 72 DPI and if any other resolution is required, this must be achieved through scaling. Set it to false to add images with the default RTF resolution.
- writeImageScalingInformation (Boolean)
- Whether to write additional styling information that is required to display scaled images correctly in Word 2000, Word 97 and Word for Mac. Defaults to false. If you want images to be scaled correctly in Word 2000, Word 97 and Word for Mac set this setting to true. Must be false for images to be displayed correctly in Word XP.
- imageWrittenAsBinary (Boolean)
- This setting controls whether images are written as binary data in the RTF document, or are hex encoded. Defaults to true for document size reasons. Set to false if you want hex encoded image data.
Document document = new Document();
RtfWriter2 writer2 = RtfWriter2.getInstance(document,
new FileOutputStream("rtfDocumentSettings.rtf"));
// Access the RtfDocumentSettings and set the desired properties
writer2.getRtfDocumentSettings().setDataCacheStyle(RtfDataCache.CACHE_DISK);
document.open();
...
document.close();
Example: java
com.lowagie.examples.rtf.documentsettings.DocumentSettings
Generates a simple document with modified document settings: see DocumentSettings.rtf
Extra jars needed in your CLASSPATH: itext-rtf.jar
Generates a simple document with modified document settings: see DocumentSettings.rtf
Extra jars needed in your CLASSPATH: itext-rtf.jar
Viewer version settings:
The RtfDocumentSettings also provides a number of
methods to set generation options for specific viewers. These act as shortcuts to
set a number of the generation settings listed above. Methods for the following viewers
are provided
You should only call one of these methods as they are partially mutually exclusive.
Go to top of the page- Word 2000 and 97: Sets the options for Word 2000 and Word 97 compliance - outputTableRowDefinitionAfter = true and writeImageScalingInformation = true
- Word for Mac: Sets the options for Word for Mac compliance - writeImageScalingInformation = true
- Word XP: Sets the options for Word XP compliance - writeImageScalingInformation = false
- OpenOffice.org: Sets the options for OpenOffice.org compliance - outputTableRowDefinitionAfter = true
You should only call one of these methods as they are partially mutually exclusive.

