Tutorial: iText by Example

Direct Content

Direct Content:
The RtfWriter2 provides components for most of the RTF specification, but not for everything. This is where the RtfDirectContent comes into play. Using this object arbitrary RTF code can be added into the document "as is". The RtfDirectContent provides no further support for adding RTF content and it is up to the creator to specify correct RTF code.

The RtfDirectContent provides one predefined constant and that is the RTF code for a soft line-break.
// Add the contents before the linebreak
par.add("This paragraph contains a soft linebreak");

// Add the soft linebreak
par.add(RtfDirectContent.DIRECT_SOFT_LINEBREAK);

// Add the contents after the linebreak
par.add("just before the just.");
    	  
Example: java com.lowagie.examples.rtf.features.direct.SoftLineBreak
Generates a document demonstrating the use of soft linebreaks: see SoftLineBreak.rtf
Extra jars needed in your CLASSPATH: itext-rtf.jar
Go to top of the page
Importing RTF documents:
The RtfWriter2 also provides an interface for importing existing RTF documents via two methods
  • RtfWriter2.importRtfDocument: Imports a complete RTF document. Will attempt to automagically translate the font and colour numbers in the original RTF document into the font and colour numbers used in the new RTF document.
  • RtfWriter2.importRtfFragment: Imports an RTF fragment. A RtfImportMappings must be provided that describes the mappings between the font and colour numbers in the imported RTF fragment to actual colours and font names.

While the importRtfFragment method is stable, the importRtfDocument should currently be considered alpha quality code. Simple RTF documents should work, but complex documents can lead to problems.

More detailed documentation will be forthcoming, when the stability of the code improves.
Go to top of the page

iText, the #1 Java-PDF library




Amazon books:
amazon.co.uk-link