Question

Currently I'm working on a simple Mail-Merge module.

I need to load plain *.RTF template, then replace all words enclosed in [[field]] tags and at the end and print them out.

I found the iText library which is free and capable of loading/saving pdfs and rtf. I managed to load rtf, merge a few copies to one huge doc but I have no idea how to replace [[field]] by custom data like customer name/address.

Is that feature present, and if yes - how to do it? The solution platform is c#/.NET

Was it helpful?

Solution 2

Finally I decided to use *.docx and "Open XML SDK 2.0 for Microsoft Office" .NET strongly typed wrapper.

OTHER TIPS

I don't think that pdf is the way you want to go.

According to this article it is extremely difficult at best and not possible at worst.

Would something like RTFLib work better for you?

G-Man

You can use RichTextBox control to find/replace placeholders.

RichTextBox rtb = new RichTextBox(); 
rtb.LoadFile("template.rtf");
string placeHolder = "[[placeholder_name]]"; 
int pos = rtb.Find(placeHolder); 
rtb.Select(pos, placeHolder.Length);
rtb.SelectedText = "new value";

After this you can get rtf formatted text with:

rtb.Rtf;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top