Pages

Wednesday 4 September 2013

Mail merge functionality using RTF template file.

Overview

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.

Steps to Merge RTF template and Java Context:


  • Step Parse RTF model source (1) consist to load RTF model source into RTFDocument structure .RTFDocument contains the whole RTF model, which split RTF elements interpretated by RTFTemplate as fields (RTFField), bookmarks (RTFBookmark)...
  • Step Transform RTF Document (2) consist to transform the RTFDocument structure, in other words:
    1. replace RTF code with specific macro swith template engine selected (ex : replace bookmark with#foreach macro when RTFTemplate is used with Velocity).
    2. remove some RTF code. For merge fields (MERGEFIELD), RTFTemplate remove the character " which include merge fields.









Steps for office Integration

  • RTF  template  can  be  created  with  MS  Word  by,  using MERGEFIELD,  HYPERLINK and BOOKMARK (cf. RTF specification).
  • This template will be merged with  Java objects  (can be  from database, LDAP etc.) and RTF  file will be generated at particular target.
  • These files can be saved in RTF as well as PDF format.
  • The generated files can be printed or send by email.



References:-
http://sourceforge.net/projects/rtftemplate/

http://rtftemplate.sourceforge.net/

Examples.

Address example.
Dependency example.