RTFTemplate is RTF engine RTF to RTF, which is able to generate RTF by merging template RTF (model RTF source) with JAVA object (context). RTFTemplate use Velocity for merging template with JAVA object. Use case with RTF template is :
It exist too version of RTFTemplate for C#. Go to NRTFTemplate page for more information.
Two steps are necessary for RTF generation if RTF model (source) is designed by MS Word :
Here an example of RTF model source designed by MS Word:
After merging RTF model source with context, RTF target generated is :
Here example code for generate RTF (Step 1 and 2) :
/* * Create a new instance of the VelocityEngine * Using stock configuration in this example, but this could instead be the VelocityEngine in general * use by your servlet(s) for example */ VelocityEngine ve = new VelocityEngine(); ve.init(); /* * Create a new RTFTemplateEngine */ RTFTemplateEngine engine = new RTFTemplateEngine( ve ); /* * Set any common formatting objects on the engine - these will be passed through to each template it creates */ engine.setDefaultFormat(Date.class, DateFormat.getDateInstance()); /* * Create a common inner context */ Context ctx = new VelocityContext(); ctx.put("date", new Date()); /* * Create and merge template for the model of Project Velocity */ RTFTemplate template = engine.createTemplate( new File("source_project.rtf") ); template.setInnerContext( ctx ); template.put("project", new Project("Jakarta Velocity project")); template.merge("project_velocity.rtf.out.rtf"); /* * Create and merge template for the model of Project RTFTemplate */ template.put("project", new Project("RTFTemplate Project")); template.merge("project_rtftemplate.rtf.out.rtf");