* 3. Get RTF Document of the rtf source model
*/
String rtfSourceModel = "test.rtf";
InputStream inputStream = TestFreemarkerTransformer.class.getResourceAsStream(rtfSourceModel);
parser.parse(inputStream);
RTFDocument document = parser.getRTFDocument();
/**
* 4. Prepare RTF context fields
* => set the field which must be transformed
* In test.rtf, there is a mergefield called "date"
*/
RTFContextFields context = new RTFContextFields();
RTFContextField field = new RTFContextField();
field.setName("$date");
context.addMergeField(field);
/**
* 5. Get the RTF freemarker transformer
*/
IRTFDocumentTransformer freemarkerTransformer =
builder.
newRTFDocumentTransformer(RTFTemplateBuilder.FREEMARKER_TRANSFORMER);
RTFDocument transformedDocument = freemarkerTransformer.transform(document, context);
/**
* 6. Display transformed RTFDocument
*/
Reader reader = transformedDocument.getReader();
BufferedReader br = new BufferedReader(reader);
int c;
while ((c = br.read()) != -1) {
System.out.print((char)c);
}