File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Best way to 'mail merge' rtf files (including images) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Best way to Watch "Best way to New topic

Best way to 'mail merge' rtf files (including images)

Joe Bloggs

Joined: Oct 30, 2008
Posts: 2
I am trying to generate doc/rtf files based on server data.

I've tried generating the files from scratch using iText. However there are dozens of letter templates to generate, and what takes minutes to design in Word takes hours to design in a Java program. Besides, the boss has just stated that she would like to be able to change the templates herself.

The obvious solution should have been an automated 'mail merge' process, but iText can only write rtf files, not read them. ( I would have thought find & replace would have been a much simpler process than generating an rtf from scratch, but so far I haven't managed to find a tool that allows this in a straightforward manner.

RtfTemplate seems to have something to do with what I want, but the 'English' documentation is incomprehensible to me.

At this point we are willing to pay money for an off-the-shelf solution if there is one.

It would need to be able to handle inserting images at marked positions in the document, as well.

[ UD: fixed URL ]
[ December 01, 2008: Message edited by: Ulf Dittmer ]
Joe Bloggs

Joined: Oct 30, 2008
Posts: 2
Help anybody? Is iText getting an update in this direction anytime soon?
Burton Rhodes

Joined: Nov 30, 2008
Posts: 2
I am struggling with the same problem/requirement. Did you find a solution to this?!?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
iText will never be able to do this; it's a write-only API. While RTFs could be read, altered and changed, PDFs can't, and they are really the root of iText - RTFs are just an add-on.

I'd create the RTFs manually (e.g. using Word), and do the replacements with string/text processing. The elements to be replaced could be marked something like [[name]], [[content]], [[image1]] etc. If the templates are to be altered manually, then the merge code would have to validate them before processing.
Anurag Setia

Joined: Dec 13, 2008
Posts: 1
Try RTFTemplate, its has simple merge feature
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Welcome to JavaRanch Burton Rhodes and Anurag Setia.
I agree. Here's the link:
subject: Best way to 'mail merge' rtf files (including images)
It's not a secret anymore!